Commit 82bdd23f authored by hyatt's avatar hyatt

Land the new "NSView-less" buttons. With this landing both

	<input type=button> and <button> will now look like OS X-style
	widgets.  Customization of background and border is not yet
	enabled, but this is still a big improvement over the old
	AppKit widgets.

        Reviewed by mjs

        * ForwardingHeaders/qpushbutton.h: Removed.
        * WebCore.xcodeproj/project.pbxproj:
        * khtml/css/cssstyleselector.cpp:
        (khtml::CSSStyleSelector::adjustRenderStyle):
        * khtml/css/cssstyleselector.h:
        (khtml::CSSStyleSelector::paintMetrics):
        * khtml/css/cssvalues.in:
        * khtml/css/html4.css:
        * khtml/html/html_formimpl.cpp:
        (DOM::HTMLButtonElementImpl::createRenderer):
        (DOM::HTMLInputElementImpl::click):
        (DOM::HTMLInputElementImpl::createRenderer):
        * khtml/html/html_formimpl.h:
        (DOM::HTMLInputElementImpl::isTextButton):
        * khtml/rendering/render_button.cpp: Added.
        (khtml::m_inner):
        (khtml::RenderButton::~RenderButton):
        (khtml::RenderButton::addChild):
        (khtml::RenderButton::removeChild):
        (khtml::RenderButton::setStyle):
        (khtml::RenderButton::updateFromElement):
        * khtml/rendering/render_button.h: Added.
        (khtml::RenderButton::removeLeftoverAnonymousBoxes):
        (khtml::RenderButton::renderName):
        * khtml/rendering/render_form.cpp:
        * khtml/rendering/render_form.h:
        (khtml::RenderFileButton::calcReplacedHeight):
        (khtml::RenderFileButton::isEditable):
        * khtml/rendering/render_style.h:
        (khtml::):
        * khtml/rendering/render_theme.cpp:
        (khtml::RenderTheme::adjustStyle):
        (khtml::RenderTheme::paint):
        (khtml::RenderTheme::adjustCheckboxStyle):
        (khtml::RenderTheme::adjustRadioStyle):
        (khtml::RenderTheme::adjustButtonStyle):
        * khtml/rendering/render_theme.h:
        (khtml::RenderTheme::setButtonSize):
        * khtml/rendering/render_theme_mac.h:
        * khtml/rendering/render_theme_mac.mm:
        (khtml::RenderThemeMac::setSizeFromFont):
        (khtml::RenderThemeMac::setFontFromControlSize):
        (khtml::RenderThemeMac::addIntrinsicMargins):
        (khtml::RenderThemeMac::setButtonPaddingFromControlSize):
        (khtml::RenderThemeMac::adjustButtonStyle):
        (khtml::RenderThemeMac::buttonSizes):
        (khtml::RenderThemeMac::buttonMargins):
        (khtml::RenderThemeMac::setButtonSize):
        (khtml::RenderThemeMac::setButtonCellState):
        (khtml::RenderThemeMac::paintButton):
        * kwq/KWQAccObject.mm:
        (-[KWQAccObject actionElement]):
        (-[KWQAccObject role]):
        (-[KWQAccObject title]):
        * kwq/KWQButton.h: Removed.
        * kwq/KWQButton.mm: Removed.
        * kwq/KWQComboBox.mm:
        * kwq/KWQLineEdit.h:
        * kwq/KWQLineEdit.mm:
        * kwq/KWQPushButton.h: Removed.
        * kwq/KWQPushButton.mm: Removed.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@10888 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 4b77d7a4
2005-10-21 David Hyatt <hyatt@apple.com>
Land the new "NSView-less" buttons. With this landing both
<input type=button> and <button> will now look like OS X-style
widgets. Customization of background and border is not yet
enabled, but this is still a big improvement over the old
AppKit widgets.
Reviewed by mjs
* ForwardingHeaders/qpushbutton.h: Removed.
* WebCore.xcodeproj/project.pbxproj:
* khtml/css/cssstyleselector.cpp:
(khtml::CSSStyleSelector::adjustRenderStyle):
* khtml/css/cssstyleselector.h:
(khtml::CSSStyleSelector::paintMetrics):
* khtml/css/cssvalues.in:
* khtml/css/html4.css:
* khtml/html/html_formimpl.cpp:
(DOM::HTMLButtonElementImpl::createRenderer):
(DOM::HTMLInputElementImpl::click):
(DOM::HTMLInputElementImpl::createRenderer):
* khtml/html/html_formimpl.h:
(DOM::HTMLInputElementImpl::isTextButton):
* khtml/rendering/render_button.cpp: Added.
(khtml::m_inner):
(khtml::RenderButton::~RenderButton):
(khtml::RenderButton::addChild):
(khtml::RenderButton::removeChild):
(khtml::RenderButton::setStyle):
(khtml::RenderButton::updateFromElement):
* khtml/rendering/render_button.h: Added.
(khtml::RenderButton::removeLeftoverAnonymousBoxes):
(khtml::RenderButton::renderName):
* khtml/rendering/render_form.cpp:
* khtml/rendering/render_form.h:
(khtml::RenderFileButton::calcReplacedHeight):
(khtml::RenderFileButton::isEditable):
* khtml/rendering/render_style.h:
(khtml::):
* khtml/rendering/render_theme.cpp:
(khtml::RenderTheme::adjustStyle):
(khtml::RenderTheme::paint):
(khtml::RenderTheme::adjustCheckboxStyle):
(khtml::RenderTheme::adjustRadioStyle):
(khtml::RenderTheme::adjustButtonStyle):
* khtml/rendering/render_theme.h:
(khtml::RenderTheme::setButtonSize):
* khtml/rendering/render_theme_mac.h:
* khtml/rendering/render_theme_mac.mm:
(khtml::RenderThemeMac::setSizeFromFont):
(khtml::RenderThemeMac::setFontFromControlSize):
(khtml::RenderThemeMac::addIntrinsicMargins):
(khtml::RenderThemeMac::setButtonPaddingFromControlSize):
(khtml::RenderThemeMac::adjustButtonStyle):
(khtml::RenderThemeMac::buttonSizes):
(khtml::RenderThemeMac::buttonMargins):
(khtml::RenderThemeMac::setButtonSize):
(khtml::RenderThemeMac::setButtonCellState):
(khtml::RenderThemeMac::paintButton):
* kwq/KWQAccObject.mm:
(-[KWQAccObject actionElement]):
(-[KWQAccObject role]):
(-[KWQAccObject title]):
* kwq/KWQButton.h: Removed.
* kwq/KWQButton.mm: Removed.
* kwq/KWQComboBox.mm:
* kwq/KWQLineEdit.h:
* kwq/KWQLineEdit.mm:
* kwq/KWQPushButton.h: Removed.
* kwq/KWQPushButton.mm: Removed.
2005-10-19 Darin Adler <darin@apple.com>
Reviewed by Maciej.
......
This diff is collapsed.
......@@ -995,7 +995,7 @@ void CSSStyleSelector::adjustRenderStyle(RenderStyle* style, ElementImpl *e)
// Let the theme get a crack at changing the style if an appearance has been set.
if (style->hasAppearance())
theme()->adjustStyle(style);
theme()->adjustStyle(this, style, e);
// Only use slow repaints if we actually have a background image.
// FIXME: We only need to invalidate the fixed regions when scrolling. It's total overkill to
......
......@@ -139,6 +139,8 @@ namespace khtml
QColor getColorFromPrimitiveValue(DOM::CSSPrimitiveValueImpl* primitiveValue);
QPaintDeviceMetrics* paintMetrics() const { return paintDeviceMetrics; }
protected:
/* checks if a compound selector (which can consist of multiple simple selectors)
......
......@@ -440,8 +440,9 @@ after-white-space
#
checkbox
radio
push-button
square-button
button
button-bevel
listbox
listitem
menulist
......
......@@ -278,15 +278,8 @@ fieldset {
}
button {
border: 2px outset ButtonFace;
background-color: ButtonFace;
color: ButtonText;
padding: 2px 2px 2px 2px;
cursor: default
}
button:active {
border-style: inset
cursor: default;
-khtml-appearance: button
}
input, textarea {
......@@ -299,7 +292,7 @@ input, textarea, select, button {
font: 11px 'Lucida Grande';
color: initial;
display: inline-block;
-khtml-box-sizing: border-box
box-sizing: border-box
}
input[type="hidden"] {
......@@ -311,6 +304,16 @@ input[type="radio"], input[type="checkbox"] {
-khtml-user-select: ignore
}
input[type="button"], input[type="submit"], input[type="reset"]
{
-khtml-appearance: push-button
}
input[type="button"], input[type="submit"], input[type="reset"], button {
-khtml-box-align: center;
text-align:center;
}
select, button, input[type="button"], input[type="image"], input[type="submit"], input[type="reset"], img {
-khtml-user-select: ignore
}
......
......@@ -46,6 +46,7 @@
#include "khtml_ext.h"
#include "rendering/render_form.h"
#include "render_button.h"
#include "render_theme.h"
#include <kcharsets.h>
......@@ -1200,6 +1201,11 @@ HTMLButtonElementImpl::~HTMLButtonElementImpl()
{
}
RenderObject* HTMLButtonElementImpl::createRenderer(RenderArena* arena, RenderStyle* style)
{
return new (arena) RenderButton(this);
}
DOMString HTMLButtonElementImpl::type() const
{
return getAttribute(typeAttr);
......@@ -1699,17 +1705,7 @@ void HTMLInputElementImpl::click(bool sendMouseEvents, bool showPressedLook)
break;
case SUBMIT:
case RESET:
case BUTTON:
#if APPLE_CHANGES
{
QWidget *widget;
if (showPressedLook && renderer() && (widget = static_cast<RenderWidget *>(renderer())->widget())) {
// using this method gives us nice Cocoa user interface feedback
static_cast<QButton *>(widget)->click(sendMouseEvents);
break;
}
}
#endif
case BUTTON:
HTMLGenericFormElementImpl::click(sendMouseEvents, showPressedLook);
break;
case FILE:
......@@ -1919,12 +1915,13 @@ RenderObject *HTMLInputElementImpl::createRenderer(RenderArena *arena, RenderSty
case CHECKBOX:
case RADIO:
return RenderObject::createObject(this, style);
case SUBMIT: return new (arena) RenderSubmitButton(this);
case SUBMIT:
case RESET:
case BUTTON:
return new (arena) RenderButton(this);
case IMAGE: return new (arena) RenderImageButton(this);
case RESET: return new (arena) RenderResetButton(this);
case FILE: return new (arena) RenderFileButton(this);
case BUTTON: return new (arena) RenderPushButton(this);
#if APPLE_CHANGES
#if APPLE_CHANGES
case RANGE: return new (arena) RenderSlider(this);
#endif
case HIDDEN: break;
......
......@@ -251,6 +251,8 @@ public:
};
DOMString type() const;
virtual khtml::RenderObject *createRenderer(RenderArena*, khtml::RenderStyle*);
virtual void parseMappedAttribute(MappedAttributeImpl *attr);
virtual void defaultEventHandler(EventImpl *evt);
......@@ -346,6 +348,8 @@ public:
virtual bool isChecked() const { return checked(); }
bool isTextButton() const { return m_type == SUBMIT || m_type == RESET || m_type == BUTTON; }
bool checked() const { return m_checked; }
void setChecked(bool);
int maxLength() const { return m_maxLen; }
......
/**
* This file is part of the html renderer for KDE.
*
* Copyright (C) 2005 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#include "config.h"
#include "render_button.h"
#include "render_text.h"
#include "htmlnames.h"
#include "html_formimpl.h"
using namespace DOM;
using namespace HTMLNames;
namespace khtml {
RenderButton::RenderButton(NodeImpl* node)
:RenderFlexibleBox(node), m_buttonText(0), m_inner(0)
{
}
RenderButton::~RenderButton()
{
}
void RenderButton::addChild(RenderObject *newChild, RenderObject *beforeChild)
{
if (!m_inner) {
// Create an anonymous block.
assert(!m_first);
m_inner = createAnonymousBlock();
m_inner->style()->setBoxFlex(1.0f);
RenderFlexibleBox::addChild(m_inner);
}
m_inner->addChild(newChild, beforeChild);
}
void RenderButton::removeChild(RenderObject *oldChild)
{
if (oldChild == m_inner || !m_inner) {
RenderFlexibleBox::removeChild(oldChild);
m_inner = 0;
}
else
m_inner->removeChild(oldChild);
}
void RenderButton::setStyle(RenderStyle* style)
{
RenderBlock::setStyle(style);
if (m_buttonText)
m_buttonText->setStyle(style);
}
void RenderButton::updateFromElement()
{
// If we're an input element, we may need to change our button text.
if (element()->hasTagName(inputTag)) {
HTMLInputElementImpl* input = static_cast<HTMLInputElementImpl*>(element());
DOMString value = input->value();
if (value.isEmpty()) {
if (m_buttonText) {
m_buttonText->destroy();
m_buttonText = 0;
}
} else {
if (m_buttonText)
m_buttonText->setText(value.impl());
else {
m_buttonText = new (renderArena()) RenderText(document(), value.impl());
m_buttonText->setStyle(style());
addChild(m_buttonText);
}
}
}
}
}
/*
* This file is part of the html renderer for KDE.
*
* Copyright (C) 2005 Apple Computer
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#ifndef render_button_h
#define render_button_h
#include "render_flexbox.h"
namespace khtml
{
// RenderButtons are just like normal flexboxes except that they will generate an anonymous block child.
// For inputs, they will also generate an anonymous RenderText and keep its style and content up
// to date as the button changes.
class RenderButton : public RenderFlexibleBox
{
public:
RenderButton(DOM::NodeImpl* node);
virtual ~RenderButton();
virtual void addChild(RenderObject *newChild, RenderObject *beforeChild = 0);
virtual void removeChild(RenderObject *oldChild);
virtual void removeLeftoverAnonymousBoxes() {};
virtual void setStyle(RenderStyle* style);
virtual void updateFromElement();
virtual const char *renderName() const { return "RenderButton"; }
protected:
RenderText* m_buttonText;
RenderBlock* m_inner;
};
};
#endif
......@@ -254,112 +254,6 @@ void RenderFormElement::slotSelectionChanged()
#endif
// -------------------------------------------------------------------------
RenderButton::RenderButton(HTMLGenericFormElementImpl *element)
: RenderFormElement(element)
{
}
short RenderButton::baselinePosition( bool f, bool isRootLineBox ) const
{
#if APPLE_CHANGES
return RenderFormElement::baselinePosition( f, isRootLineBox );
#else
return RenderWidget::baselinePosition( f, isRootLineBox ) - 2;
#endif
}
// -------------------------------------------------------------------------------
RenderSubmitButton::RenderSubmitButton(HTMLInputElementImpl *element)
: RenderButton(element)
{
QPushButton* p = new QPushButton(view()->viewport());
setQWidget(p);
p->setAutoMask(true);
p->setMouseTracking(true);
connect(p, SIGNAL(clicked()), this, SLOT(slotClicked()));
}
QString RenderSubmitButton::rawText()
{
QString value = element()->valueWithDefault().qstring();
value = value.stripWhiteSpace();
value.replace(QChar('\\'), backslashAsCurrencySymbol());
#if APPLE_CHANGES
return value;
#else
QString raw;
for(unsigned int i = 0; i < value.length(); i++) {
raw += value[i];
if(value[i] == '&')
raw += '&';
}
return raw;
#endif
}
void RenderSubmitButton::calcMinMaxWidth()
{
KHTMLAssert( !minMaxKnown() );
#if APPLE_CHANGES
// Let the widget tell us how big it wants to be.
QSize s(widget()->sizeHint());
setIntrinsicWidth(s.width());
setIntrinsicHeight(s.height());
#else
QString raw = rawText();
QPushButton* pb = static_cast<QPushButton*>(m_widget);
pb->setText(raw);
pb->setFont(style()->font());
bool empty = raw.isEmpty();
if ( empty )
raw = QString::fromLatin1("XXXX");
QFontMetrics fm = pb->fontMetrics();
int margin = pb->style().pixelMetric( QStyle::PM_ButtonMargin, pb);
QSize s(pb->style().sizeFromContents(
QStyle::CT_PushButton, pb, fm.size( ShowPrefix, raw))
.expandedTo(QApplication::globalStrut()));
setIntrinsicWidth( s.width() - margin / 2 );
setIntrinsicHeight( s.height() - margin / 2);
#endif
RenderButton::calcMinMaxWidth();
}
#if APPLE_CHANGES
void RenderSubmitButton::setStyle(RenderStyle *s)
{
RenderButton::setStyle(s);
QPushButton *w = static_cast<QPushButton*>(m_widget);
w->setWritingDirection(style()->direction() == RTL ? QPainter::RTL : QPainter::LTR);
}
#endif
void RenderSubmitButton::updateFromElement()
{
QPushButton *w = static_cast<QPushButton*>(m_widget);
QString oldText = w->text();
QString newText = rawText();
w->setText(newText);
if ( oldText != newText )
setNeedsLayoutAndMinMaxRecalc();
RenderFormElement::updateFromElement();
}
short RenderSubmitButton::baselinePosition( bool f, bool isRootLineBox ) const
{
return RenderFormElement::baselinePosition( f, isRootLineBox );
}
// -------------------------------------------------------------------------------
RenderImageButton::RenderImageButton(HTMLInputElementImpl *element)
......@@ -370,24 +264,6 @@ RenderImageButton::RenderImageButton(HTMLInputElementImpl *element)
// -------------------------------------------------------------------------------
// FIXME: No real reason to need separate classes for RenderResetButton and
// RenderSubmitButton now that the default label is handled on the DOM side.
RenderResetButton::RenderResetButton(HTMLInputElementImpl *element)
: RenderSubmitButton(element)
{
}
// -------------------------------------------------------------------------------
// FIXME: No real reason to need separate classes for RenderPushButton and
// RenderSubmitButton now that the default label is handled on the DOM side.
RenderPushButton::RenderPushButton(HTMLInputElementImpl *element)
: RenderSubmitButton(element)
{
}
// -------------------------------------------------------------------------------
#if !APPLE_CHANGES
LineEditWidget::LineEditWidget(QWidget *parent)
......
......@@ -36,7 +36,6 @@ class QListboxItem;
#include <qtextedit.h>
#include <klineedit.h>
#include <qpushbutton.h>
#include <qhbox.h>
#include <klistbox.h>
#include <kcombobox.h>
......@@ -110,7 +109,6 @@ public slots:
#endif
protected:
virtual bool isRenderButton() const { return false; }
virtual bool isEditable() const { return false; }
AlignmentFlags textAlignment() const;
......@@ -118,51 +116,6 @@ protected:
// -------------------------------------------------------------------------
// generic class for all buttons
class RenderButton : public RenderFormElement
{
Q_OBJECT
public:
RenderButton(DOM::HTMLGenericFormElementImpl* node);
#if APPLE_CHANGES
int calcReplacedHeight() const { return intrinsicHeight(); }
virtual bool canHaveIntrinsicMargins() const { return true; }
#endif
virtual const char *renderName() const { return "RenderButton"; }
virtual short baselinePosition( bool, bool ) const;
// don't even think about making this method virtual!
DOM::HTMLInputElementImpl* element() const
{ return static_cast<DOM::HTMLInputElementImpl*>(RenderObject::element()); }
protected:
virtual bool isRenderButton() const { return true; }
};
// -------------------------------------------------------------------------
class RenderSubmitButton : public RenderButton
{
public:
RenderSubmitButton(DOM::HTMLInputElementImpl *element);
virtual const char *renderName() const { return "RenderSubmitButton"; }
virtual void calcMinMaxWidth();
virtual void updateFromElement();
virtual short baselinePosition( bool, bool ) const;
#if APPLE_CHANGES
virtual void setStyle(RenderStyle *);
#endif
private:
QString rawText();
};
// -------------------------------------------------------------------------
class RenderImageButton : public RenderImage
{
public:
......@@ -172,25 +125,6 @@ public:
virtual bool isImageButton() const { return true; }
};
// -------------------------------------------------------------------------
class RenderResetButton : public RenderSubmitButton
{
public:
RenderResetButton(DOM::HTMLInputElementImpl *element);
virtual const char *renderName() const { return "RenderResetButton"; }
};
// -------------------------------------------------------------------------
class RenderPushButton : public RenderSubmitButton
{
public:
RenderPushButton(DOM::HTMLInputElementImpl *element);
};
// -------------------------------------------------------------------------
class RenderLineEdit : public RenderFormElement
......@@ -284,20 +218,12 @@ public:
virtual void updateFromElement();
void select();
#if APPLE_CHANGES
int calcReplacedHeight() const { return intrinsicHeight(); }
#endif
DOM::HTMLInputElementImpl *element() const
{ return static_cast<DOM::HTMLInputElementImpl*>(RenderObject::element()); }
#if !APPLE_CHANGES
KLineEdit* lineEdit() const { return m_edit; }
#endif
#if APPLE_CHANGES
void click(bool sendMouseEvents);
#endif
public slots:
virtual void slotClicked();
......@@ -306,13 +232,6 @@ public slots:
protected: