[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

darin darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 07:56:37 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit e421ce856b3c0d578ab9a710ff2280eef03f8de1
Author: darin <darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Sep 19 21:46:47 2003 +0000

    WebCore:
    
            Reviewed by Dave.
    
            - do the prep work for the mini controls feature; Dave will finish this
    
            * khtml/rendering/render_form.cpp: (RenderFormElement::updateFromElement):
            Tell the widget about the font size. Our widgets use the font size to
            decide whether to use Aqua normal, small, or mini.
    
            * kwq/KWQButton.h: Add setFont.
            * kwq/KWQButton.mm:
            (QButton::setFont): Set control size based on font.
            (KWQNSControlSizeForFont): Determine control size given a font. Dave is going
            to tweak this later.
    
            * kwq/KWQCheckBox.h: Add dimensions function for metrics for each control size.
            * kwq/KWQCheckBox.mm:
            (QCheckBox::sizeHint): Use dimensions.
            (QCheckBox::frameGeometry): Use dimensions.
            (QCheckBox::setFrameGeometry): Use dimensions.
            (QCheckBox::baselinePosition): Use dimensions.
            (QCheckBox::dimensions): Added. Has newly tweaked values for all dimensions for
            all three control sizes.
    
            * kwq/KWQComboBox.h: Add setFont and dimensions.
            * kwq/KWQComboBox.mm:
            (QComboBox::sizeHint): Use dimensions.
            (QComboBox::frameGeometry): Use dimensions.
            (QComboBox::setFrameGeometry): Use dimensions.
            (QComboBox::baselinePosition): Use dimensions.
            (QComboBox::setFont): Use dimensions.
            (QComboBox::dimensions): Added. Has newly tweaked values for all dimensions for
            all three control sizes.
    
            * kwq/KWQFileButton.mm: (KWQFileButton::baselinePosition): Change to adapt to
            flipped version of file button NSControl.
    
            * kwq/KWQPushButton.h: Add dimensions function for metrics for each control size.
            * kwq/KWQPushButton.mm:
            (QPushButton::sizeHint): Use dimensions.
            (QPushButton::frameGeometry): Use dimensions.
            (QPushButton::setFrameGeometry): Use dimensions.
            (QPushButton::baselinePosition): Use dimensions.
            (QPushButton::dimensions): Added. Has newly tweaked values for all dimensions for
            all three control sizes.
    
            * kwq/KWQRadioButton.h: Add dimensions function for metrics for each control size.
            * kwq/KWQRadioButton.mm:
            (QRadioButton::sizeHint): Use dimensions.
            (QRadioButton::frameGeometry): Use dimensions.
            (QRadioButton::setFrameGeometry): Use dimensions.
            (QRadioButton::baselinePosition): Use dimensions.
            (QRadioButton::dimensions): Added. Has newly tweaked values for all dimensions for
            all three control sizes.
    
    WebKit:
    
            Reviewed by Dave.
    
            - do the prep work for the mini controls feature; Dave will finish this
    
            * WebCoreSupport.subproj/WebFileButton.m:
            (-[WebFileButton isFlipped]): Make this flipped, easier to understand coordinates that way.
            (-[WebFileButton drawRect:]): Update for flipped-ness.
            (-[WebFileButton visualFrame]): Update for flipped-ness.
            (-[WebFileButton setVisualFrame:]): Update for flipped-ness.
            (-[WebFileButton baseline]): Update for flipped-ness.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@5007 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2003-10-25 b/WebCore/ChangeLog-2003-10-25
index 97314b8..37d7cee 100644
--- a/WebCore/ChangeLog-2003-10-25
+++ b/WebCore/ChangeLog-2003-10-25
@@ -1,3 +1,59 @@
+2003-09-19  Darin Adler  <darin at apple.com>
+
+        Reviewed by Dave.
+
+        - do the prep work for the mini controls feature; Dave will finish this
+
+        * khtml/rendering/render_form.cpp: (RenderFormElement::updateFromElement):
+        Tell the widget about the font size. Our widgets use the font size to
+        decide whether to use Aqua normal, small, or mini.
+
+        * kwq/KWQButton.h: Add setFont.
+        * kwq/KWQButton.mm:
+        (QButton::setFont): Set control size based on font.
+        (KWQNSControlSizeForFont): Determine control size given a font. Dave is going
+        to tweak this later.
+
+        * kwq/KWQCheckBox.h: Add dimensions function for metrics for each control size.
+        * kwq/KWQCheckBox.mm:
+        (QCheckBox::sizeHint): Use dimensions.
+        (QCheckBox::frameGeometry): Use dimensions.
+        (QCheckBox::setFrameGeometry): Use dimensions.
+        (QCheckBox::baselinePosition): Use dimensions.
+        (QCheckBox::dimensions): Added. Has newly tweaked values for all dimensions for
+        all three control sizes.
+
+        * kwq/KWQComboBox.h: Add setFont and dimensions.
+        * kwq/KWQComboBox.mm:
+        (QComboBox::sizeHint): Use dimensions.
+        (QComboBox::frameGeometry): Use dimensions.
+        (QComboBox::setFrameGeometry): Use dimensions.
+        (QComboBox::baselinePosition): Use dimensions.
+        (QComboBox::setFont): Use dimensions.
+        (QComboBox::dimensions): Added. Has newly tweaked values for all dimensions for
+        all three control sizes.
+
+        * kwq/KWQFileButton.mm: (KWQFileButton::baselinePosition): Change to adapt to
+        flipped version of file button NSControl.
+
+        * kwq/KWQPushButton.h: Add dimensions function for metrics for each control size.
+        * kwq/KWQPushButton.mm:
+        (QPushButton::sizeHint): Use dimensions.
+        (QPushButton::frameGeometry): Use dimensions.
+        (QPushButton::setFrameGeometry): Use dimensions.
+        (QPushButton::baselinePosition): Use dimensions.
+        (QPushButton::dimensions): Added. Has newly tweaked values for all dimensions for
+        all three control sizes.
+
+        * kwq/KWQRadioButton.h: Add dimensions function for metrics for each control size.
+        * kwq/KWQRadioButton.mm:
+        (QRadioButton::sizeHint): Use dimensions.
+        (QRadioButton::frameGeometry): Use dimensions.
+        (QRadioButton::setFrameGeometry): Use dimensions.
+        (QRadioButton::baselinePosition): Use dimensions.
+        (QRadioButton::dimensions): Added. Has newly tweaked values for all dimensions for
+        all three control sizes.
+
 2003-09-19  Maciej Stachowiak  <mjs at apple.com>
 
         Reviewed by Darin.
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 97314b8..37d7cee 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,59 @@
+2003-09-19  Darin Adler  <darin at apple.com>
+
+        Reviewed by Dave.
+
+        - do the prep work for the mini controls feature; Dave will finish this
+
+        * khtml/rendering/render_form.cpp: (RenderFormElement::updateFromElement):
+        Tell the widget about the font size. Our widgets use the font size to
+        decide whether to use Aqua normal, small, or mini.
+
+        * kwq/KWQButton.h: Add setFont.
+        * kwq/KWQButton.mm:
+        (QButton::setFont): Set control size based on font.
+        (KWQNSControlSizeForFont): Determine control size given a font. Dave is going
+        to tweak this later.
+
+        * kwq/KWQCheckBox.h: Add dimensions function for metrics for each control size.
+        * kwq/KWQCheckBox.mm:
+        (QCheckBox::sizeHint): Use dimensions.
+        (QCheckBox::frameGeometry): Use dimensions.
+        (QCheckBox::setFrameGeometry): Use dimensions.
+        (QCheckBox::baselinePosition): Use dimensions.
+        (QCheckBox::dimensions): Added. Has newly tweaked values for all dimensions for
+        all three control sizes.
+
+        * kwq/KWQComboBox.h: Add setFont and dimensions.
+        * kwq/KWQComboBox.mm:
+        (QComboBox::sizeHint): Use dimensions.
+        (QComboBox::frameGeometry): Use dimensions.
+        (QComboBox::setFrameGeometry): Use dimensions.
+        (QComboBox::baselinePosition): Use dimensions.
+        (QComboBox::setFont): Use dimensions.
+        (QComboBox::dimensions): Added. Has newly tweaked values for all dimensions for
+        all three control sizes.
+
+        * kwq/KWQFileButton.mm: (KWQFileButton::baselinePosition): Change to adapt to
+        flipped version of file button NSControl.
+
+        * kwq/KWQPushButton.h: Add dimensions function for metrics for each control size.
+        * kwq/KWQPushButton.mm:
+        (QPushButton::sizeHint): Use dimensions.
+        (QPushButton::frameGeometry): Use dimensions.
+        (QPushButton::setFrameGeometry): Use dimensions.
+        (QPushButton::baselinePosition): Use dimensions.
+        (QPushButton::dimensions): Added. Has newly tweaked values for all dimensions for
+        all three control sizes.
+
+        * kwq/KWQRadioButton.h: Add dimensions function for metrics for each control size.
+        * kwq/KWQRadioButton.mm:
+        (QRadioButton::sizeHint): Use dimensions.
+        (QRadioButton::frameGeometry): Use dimensions.
+        (QRadioButton::setFrameGeometry): Use dimensions.
+        (QRadioButton::baselinePosition): Use dimensions.
+        (QRadioButton::dimensions): Added. Has newly tweaked values for all dimensions for
+        all three control sizes.
+
 2003-09-19  Maciej Stachowiak  <mjs at apple.com>
 
         Reviewed by Darin.
diff --git a/WebCore/khtml/rendering/render_form.cpp b/WebCore/khtml/rendering/render_form.cpp
index d4cc6d0..e91ba2f 100644
--- a/WebCore/khtml/rendering/render_form.cpp
+++ b/WebCore/khtml/rendering/render_form.cpp
@@ -79,6 +79,9 @@ short RenderFormElement::baselinePosition( bool f, bool isRootLineBox ) const
 void RenderFormElement::updateFromElement()
 {
     m_widget->setEnabled(!element()->disabled());
+#if APPLE_CHANGES
+    m_widget->setFont(style()->font());
+#endif
 
     QColor color = style()->color();
     QColor backgroundColor = style()->backgroundColor();
diff --git a/WebCore/kwq/KWQButton.h b/WebCore/kwq/KWQButton.h
index a665375..7df1f97 100644
--- a/WebCore/kwq/KWQButton.h
+++ b/WebCore/kwq/KWQButton.h
@@ -39,9 +39,16 @@ public:
     QString text() const;
     
     virtual void clicked();
+
+    // QWidget overrides
+    virtual void setFont(const QFont &);
+
 private:
-    
     KWQSignal m_clicked;
 };
 
+#ifdef __OBJC__
+NSControlSize KWQNSControlSizeForFont(const QFont &);
+#endif
+
 #endif
diff --git a/WebCore/kwq/KWQButton.mm b/WebCore/kwq/KWQButton.mm
index eda0722..4c0c051 100644
--- a/WebCore/kwq/KWQButton.mm
+++ b/WebCore/kwq/KWQButton.mm
@@ -82,7 +82,7 @@ QButton::QButton()
 
     [button setTitle:@""];
     [[button cell] setControlSize:NSSmallControlSize];
-    [button setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
+    [button setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
 
     setView(button);
 
@@ -123,3 +123,30 @@ void QButton::clicked()
         m_clicked.call();
     }
 }
+
+void QButton::setFont(const QFont &f)
+{
+    QWidget::setFont(f);
+
+    const NSControlSize size = KWQNSControlSizeForFont(f);    
+    NSControl * const button = static_cast<NSControl *>(getView());
+    [[button cell] setControlSize:size];
+    [button setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:size]]];
+}
+
+NSControlSize KWQNSControlSizeForFont(const QFont &f)
+{
+    return NSSmallControlSize;
+    // Dave is going to turn this on once he figures out what he wants to do
+    // about mini controls.
+#if 0
+    const int fontSize = f.pixelSize();
+    if (fontSize >= 20) {
+        return NSRegularControlSize;
+    }
+    if (fontSize >= 10) {
+        return NSSmallControlSize;
+    }
+    return NSMiniControlSize;
+#endif
+}
diff --git a/WebCore/kwq/KWQCheckBox.h b/WebCore/kwq/KWQCheckBox.h
index 243f1b7..8735229 100644
--- a/WebCore/kwq/KWQCheckBox.h
+++ b/WebCore/kwq/KWQCheckBox.h
@@ -43,6 +43,8 @@ public:
     virtual void clicked();
 
 private:
+    const int *dimensions() const;
+
     KWQSignal m_stateChanged;
 };
 
diff --git a/WebCore/kwq/KWQCheckBox.mm b/WebCore/kwq/KWQCheckBox.mm
index f513abe..0e39ef9 100644
--- a/WebCore/kwq/KWQCheckBox.mm
+++ b/WebCore/kwq/KWQCheckBox.mm
@@ -25,18 +25,15 @@
 
 #import "KWQCheckBox.h"
 
-// We empirically determined that check boxes have these dimensions.
-// It would be better to get this info from AppKit somehow.
-
-#define TOP_MARGIN 4
-#define BOTTOM_MARGIN 3
-#define LEFT_MARGIN 3
-#define RIGHT_MARGIN 3
-
-#define WIDTH 12
-#define HEIGHT 12
-
-#define BASELINE_MARGIN 2
+enum {
+    topMargin,
+    bottomMargin,
+    leftMargin,
+    rightMargin,
+    baselineFudgeFactor,
+    dimWidth,
+    dimHeight
+};
 
 QCheckBox::QCheckBox(QWidget *w)
     : m_stateChanged(this, SIGNAL(stateChanged(int)))
@@ -47,22 +44,22 @@ QCheckBox::QCheckBox(QWidget *w)
 
 QSize QCheckBox::sizeHint() const 
 {
-    return QSize(WIDTH, HEIGHT);
+    return QSize(dimensions()[dimWidth], dimensions()[dimHeight]);
 }
 
 QRect QCheckBox::frameGeometry() const
 {
     QRect r = QWidget::frameGeometry();
-    return QRect(r.x() + LEFT_MARGIN, r.y() + TOP_MARGIN,
-        r.width() - (LEFT_MARGIN + RIGHT_MARGIN),
-        r.height() - (TOP_MARGIN + BOTTOM_MARGIN));
+    return QRect(r.x() + dimensions()[leftMargin], r.y() + dimensions()[topMargin],
+        r.width() - (dimensions()[leftMargin] + dimensions()[rightMargin]),
+        r.height() - (dimensions()[topMargin] + dimensions()[bottomMargin]));
 }
 
 void QCheckBox::setFrameGeometry(const QRect &r)
 {
-    QWidget::setFrameGeometry(QRect(r.x() - LEFT_MARGIN, r.y() - TOP_MARGIN,
-        r.width() + LEFT_MARGIN + RIGHT_MARGIN,
-        r.height() + TOP_MARGIN + BOTTOM_MARGIN));
+    QWidget::setFrameGeometry(QRect(r.x() - dimensions()[leftMargin], r.y() - dimensions()[topMargin],
+        r.width() + dimensions()[leftMargin] + dimensions()[rightMargin],
+        r.height() + dimensions()[topMargin] + dimensions()[bottomMargin]));
 }
 
 void QCheckBox::setChecked(bool isChecked)
@@ -90,5 +87,18 @@ void QCheckBox::clicked()
 
 int QCheckBox::baselinePosition() const
 {
-    return height() - BASELINE_MARGIN;
+    return height() - dimensions()[baselineFudgeFactor];
+}
+
+const int *QCheckBox::dimensions() const
+{
+    // We empirically determined these dimensions.
+    // It would be better to get this info from AppKit somehow.
+    static const int w[3][7] = {
+        { 3, 4, 2, 4, 2, 14, 14 },
+        { 4, 3, 3, 3, 2, 12, 12 },
+        { 4, 3, 3, 3, 2, 10, 10 },
+    };
+    NSControl * const button = static_cast<NSControl *>(getView());
+    return w[[[button cell] controlSize]];
 }
diff --git a/WebCore/kwq/KWQComboBox.h b/WebCore/kwq/KWQComboBox.h
index 66600d0..440e506 100644
--- a/WebCore/kwq/KWQComboBox.h
+++ b/WebCore/kwq/KWQComboBox.h
@@ -26,9 +26,10 @@
 #ifndef QCOMBOBOX_H_
 #define QCOMBOBOX_H_
 
-#include "KWQListBox.h"
 #include "KWQWidget.h"
 
+class QListBox;
+
 #ifdef __OBJC__
 @class KWQComboBoxAdapter;
 #else
@@ -53,11 +54,13 @@ public:
     QRect frameGeometry() const;
     void setFrameGeometry(const QRect &);
     int baselinePosition() const;
+    void setFont(const QFont &);
 
     void itemSelected();
 
 private:
     bool updateCurrentItem() const;
+    const int *dimensions() const;
     
     KWQComboBoxAdapter *_adapter;
     mutable float _width;
diff --git a/WebCore/kwq/KWQComboBox.mm b/WebCore/kwq/KWQComboBox.mm
index 933a1dc..7e89097 100644
--- a/WebCore/kwq/KWQComboBox.mm
+++ b/WebCore/kwq/KWQComboBox.mm
@@ -25,29 +25,25 @@
 
 #import "KWQComboBox.h"
 
+#import "KWQButton.h"
 #import "KWQView.h"
 #import "KWQKHTMLPart.h"
 #import "WebCoreBridge.h"
 
 #import "khtmlview.h"
 #import "render_replaced.h"
-using khtml::RenderWidget;
-
-// We empirically determined that combo boxes have these extra pixels on all
-// sides. It would be better to get this info from AppKit somehow.
-#define TOP_MARGIN 1
-#define BOTTOM_MARGIN 3
-#define LEFT_MARGIN 3
-#define RIGHT_MARGIN 3
 
-// This is the 2-pixel CELLOFFSET for bordered cells from NSCell.
-#define VERTICAL_FUDGE_FACTOR 2
+using khtml::RenderWidget;
 
-// When we discovered we needed to measure text widths ourselves, I empirically
-// determined these widths. I don't know what exactly they correspond to in the
-// NSPopUpButtonCell code.
-#define WIDTH_NOT_INCLUDING_TEXT 31
-#define MINIMUM_WIDTH 36
+enum {
+    topMargin,
+    bottomMargin,
+    leftMargin,
+    rightMargin,
+    baselineFudgeFactor,
+    widthNotIncludingText,
+    minimumTextWidth
+};
 
 @interface KWQComboBoxAdapter : NSObject
 {
@@ -82,7 +78,7 @@ QComboBox::QComboBox()
     [button setAction:@selector(action:)];
 
     [[button cell] setControlSize:NSSmallControlSize];
-    [button setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
+    [button setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
 
     setView(button);
 
@@ -135,36 +131,36 @@ QSize QComboBox::sizeHint() const
             width = MAX(width, size.width);
         }
         _width = ceil(width);
-        if (_width < MINIMUM_WIDTH - WIDTH_NOT_INCLUDING_TEXT) {
-            _width = MINIMUM_WIDTH - WIDTH_NOT_INCLUDING_TEXT;
+        if (_width < dimensions()[minimumTextWidth]) {
+            _width = dimensions()[minimumTextWidth];
         }
         _widthGood = true;
     }
     
-    return QSize((int)_width + WIDTH_NOT_INCLUDING_TEXT,
-        (int)[[button cell] cellSize].height - (TOP_MARGIN + BOTTOM_MARGIN));
+    return QSize((int)_width + dimensions()[widthNotIncludingText],
+        (int)[[button cell] cellSize].height - (dimensions()[topMargin] + dimensions()[bottomMargin]));
 }
 
 QRect QComboBox::frameGeometry() const
 {
     QRect r = QWidget::frameGeometry();
-    return QRect(r.x() + LEFT_MARGIN, r.y() + TOP_MARGIN,
-        r.width() - (LEFT_MARGIN + RIGHT_MARGIN),
-        r.height() - (TOP_MARGIN + BOTTOM_MARGIN));
+    return QRect(r.x() + dimensions()[leftMargin], r.y() + dimensions()[topMargin],
+        r.width() - (dimensions()[leftMargin] + dimensions()[rightMargin]),
+        r.height() - (dimensions()[topMargin] + dimensions()[bottomMargin]));
 }
 
 void QComboBox::setFrameGeometry(const QRect &r)
 {
-    QWidget::setFrameGeometry(QRect(-LEFT_MARGIN + r.x(), -TOP_MARGIN + r.y(),
-        LEFT_MARGIN + r.width() + RIGHT_MARGIN,
-        TOP_MARGIN + r.height() + BOTTOM_MARGIN));
+    QWidget::setFrameGeometry(QRect(-dimensions()[leftMargin] + r.x(), -dimensions()[topMargin] + r.y(),
+        dimensions()[leftMargin] + r.width() + dimensions()[rightMargin],
+        dimensions()[topMargin] + r.height() + dimensions()[bottomMargin]));
 }
 
 int QComboBox::baselinePosition() const
 {
     // Menu text is at the top.
     KWQPopUpButton *button = (KWQPopUpButton *)getView();
-    return (int)ceil(-TOP_MARGIN + VERTICAL_FUDGE_FACTOR + [[button font] ascender]);
+    return (int)ceil(-dimensions()[topMargin] + dimensions()[baselineFudgeFactor] + [[button font] ascender]);
 }
 
 void QComboBox::clear()
@@ -199,7 +195,33 @@ void QComboBox::itemSelected()
         _activated.call(_currentItem);
     }
 }
- 
+
+void QComboBox::setFont(const QFont &f)
+{
+    QWidget::setFont(f);
+
+    const NSControlSize size = KWQNSControlSizeForFont(f);
+    NSControl * const button = static_cast<NSControl *>(getView());
+    if (size != [[button cell] controlSize]) {
+        [[button cell] setControlSize:size];
+        [button setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:size]]];
+        _widthGood = false;
+    }
+}
+
+const int *QComboBox::dimensions() const
+{
+    // We empirically determined these dimensions.
+    // It would be better to get this info from AppKit somehow.
+    static const int w[3][7] = {
+        { 2, 3, 3, 3, 4, 34, 9 },
+        { 1, 3, 3, 3, 3, 31, 5 },
+        { 0, 0, 1, 1, 2, 32, 0 }
+    };
+    NSControl * const button = static_cast<NSControl *>(getView());
+    return w[[[button cell] controlSize]];
+}
+
 @implementation KWQComboBoxAdapter
 
 - initWithQComboBox:(QComboBox *)b
diff --git a/WebCore/kwq/KWQFileButton.mm b/WebCore/kwq/KWQFileButton.mm
index 6d3caa9..40b5833 100644
--- a/WebCore/kwq/KWQFileButton.mm
+++ b/WebCore/kwq/KWQFileButton.mm
@@ -84,7 +84,7 @@ void KWQFileButton::setFrameGeometry(const QRect &rect)
 int KWQFileButton::baselinePosition() const
 {
     NSView <WebCoreFileButton> *button = getView();
-    return (int)(NSMaxY([button frame]) - [button baseline] - [button visualFrame].origin.y);
+    return (int)([button frame].origin.y + [button baseline] - [button visualFrame].origin.y);
 }
 
 void KWQFileButton::filenameChanged()
diff --git a/WebCore/kwq/KWQPushButton.h b/WebCore/kwq/KWQPushButton.h
index 5191917..2b5de64 100644
--- a/WebCore/kwq/KWQPushButton.h
+++ b/WebCore/kwq/KWQPushButton.h
@@ -37,6 +37,9 @@ public:
     QRect frameGeometry() const;
     void setFrameGeometry(const QRect &);
     int baselinePosition() const;
+
+private:
+    const int *dimensions() const;
 };
 
 #endif
diff --git a/WebCore/kwq/KWQPushButton.mm b/WebCore/kwq/KWQPushButton.mm
index e0d8193..43f0563 100644
--- a/WebCore/kwq/KWQPushButton.mm
+++ b/WebCore/kwq/KWQPushButton.mm
@@ -25,15 +25,13 @@
 
 #import "KWQPushButton.h"
 
-// We empirically determined that buttons have these extra pixels on all
-// sides. It would be better to get this info from AppKit somehow.
-#define TOP_MARGIN 4
-#define BOTTOM_MARGIN 6
-#define LEFT_MARGIN 5
-#define RIGHT_MARGIN 5
-
-// AppKit calls this kThemePushButtonSmallTextOffset.
-#define VERTICAL_FUDGE_FACTOR 2
+enum {
+    topMargin,
+    bottomMargin,
+    leftMargin,
+    rightMargin,
+    baselineFudgeFactor
+};
 
 QPushButton::QPushButton(QWidget *)
 {
@@ -52,23 +50,23 @@ QPushButton::QPushButton(const QString &text, QWidget *)
 QSize QPushButton::sizeHint() const 
 {
     NSButton *button = (NSButton *)getView();
-    return QSize((int)[[button cell] cellSize].width - (LEFT_MARGIN + RIGHT_MARGIN),
-        (int)[[button cell] cellSize].height - (TOP_MARGIN + BOTTOM_MARGIN));
+    return QSize((int)[[button cell] cellSize].width - (dimensions()[leftMargin] + dimensions()[rightMargin]),
+        (int)[[button cell] cellSize].height - (dimensions()[topMargin] + dimensions()[bottomMargin]));
 }
 
 QRect QPushButton::frameGeometry() const
 {
     QRect r = QWidget::frameGeometry();
-    return QRect(r.x() + LEFT_MARGIN, r.y() + TOP_MARGIN,
-        r.width() - (LEFT_MARGIN + RIGHT_MARGIN),
-        r.height() - (TOP_MARGIN + BOTTOM_MARGIN));
+    return QRect(r.x() + dimensions()[leftMargin], r.y() + dimensions()[topMargin],
+        r.width() - (dimensions()[leftMargin] + dimensions()[rightMargin]),
+        r.height() - (dimensions()[topMargin] + dimensions()[bottomMargin]));
 }
 
 void QPushButton::setFrameGeometry(const QRect &r)
 {
-    QWidget::setFrameGeometry(QRect(r.x() - LEFT_MARGIN, r.y() - TOP_MARGIN,
-        r.width() + LEFT_MARGIN + RIGHT_MARGIN,
-        r.height() + TOP_MARGIN + BOTTOM_MARGIN));
+    QWidget::setFrameGeometry(QRect(r.x() - dimensions()[leftMargin], r.y() - dimensions()[topMargin],
+        r.width() + dimensions()[leftMargin] + dimensions()[rightMargin],
+        r.height() + dimensions()[topMargin] + dimensions()[bottomMargin]));
 }
 
 int QPushButton::baselinePosition() const
@@ -78,7 +76,20 @@ int QPushButton::baselinePosition() const
     NSFont *font = [button font];
     float ascender = [font ascender];
     float descender = [font descender];
-    return (int)ceil(-TOP_MARGIN
-        + ((height() + TOP_MARGIN + BOTTOM_MARGIN) - (ascender - descender)) / 2.0
-        + ascender - VERTICAL_FUDGE_FACTOR);
+    return (int)ceil(-dimensions()[topMargin]
+        + ((height() + dimensions()[topMargin] + dimensions()[bottomMargin]) - (ascender - descender)) / 2.0
+        + ascender - dimensions()[baselineFudgeFactor]);
+}
+
+const int *QPushButton::dimensions() const
+{
+    // We empirically determined these dimensions.
+    // It would be better to get this info from AppKit somehow.
+    static const int w[3][5] = {
+        { 4, 7, 6, 6, 2 },
+        { 4, 6, 5, 5, 2 },
+        { 0, 1, 1, 1, 1 }
+    };
+    NSControl * const button = static_cast<NSControl *>(getView());
+    return w[[[button cell] controlSize]];
 }
diff --git a/WebCore/kwq/KWQRadioButton.h b/WebCore/kwq/KWQRadioButton.h
index ad8128a..1c888eb 100644
--- a/WebCore/kwq/KWQRadioButton.h
+++ b/WebCore/kwq/KWQRadioButton.h
@@ -39,6 +39,9 @@ public:
     int baselinePosition() const;
     QRect frameGeometry() const;
     void setFrameGeometry(const QRect &);
+
+private:
+    const int *dimensions() const;
 };
 
 #endif
diff --git a/WebCore/kwq/KWQRadioButton.mm b/WebCore/kwq/KWQRadioButton.mm
index 4db5093..aa90980 100644
--- a/WebCore/kwq/KWQRadioButton.mm
+++ b/WebCore/kwq/KWQRadioButton.mm
@@ -25,20 +25,15 @@
 
 #import "KWQRadioButton.h"
 
-#import "KWQView.h"
-
-// We empirically determined that radio buttons have these dimensions.
-// It would be better to get this info from AppKit somehow.
-
-#define TOP_MARGIN 3
-#define BOTTOM_MARGIN 3
-#define LEFT_MARGIN 2
-#define RIGHT_MARGIN 2
-
-#define WIDTH 14
-#define HEIGHT 13
-
-#define BASELINE_MARGIN 2
+enum {
+    topMargin,
+    bottomMargin,
+    leftMargin,
+    rightMargin,
+    baselineFudgeFactor,
+    dimWidth,
+    dimHeight
+};
 
 QRadioButton::QRadioButton(QWidget *w)
 {
@@ -48,22 +43,22 @@ QRadioButton::QRadioButton(QWidget *w)
 
 QSize QRadioButton::sizeHint() const 
 {
-    return QSize(WIDTH, HEIGHT);
+    return QSize(dimensions()[dimWidth], dimensions()[dimHeight]);
 }
 
 QRect QRadioButton::frameGeometry() const
 {
     QRect r = QWidget::frameGeometry();
-    return QRect(r.x() + LEFT_MARGIN, r.y() + TOP_MARGIN,
-        r.width() - (LEFT_MARGIN + RIGHT_MARGIN),
-        r.height() - (TOP_MARGIN + BOTTOM_MARGIN));
+    return QRect(r.x() + dimensions()[leftMargin], r.y() + dimensions()[topMargin],
+        r.width() - (dimensions()[leftMargin] + dimensions()[rightMargin]),
+        r.height() - (dimensions()[topMargin] + dimensions()[bottomMargin]));
 }
 
 void QRadioButton::setFrameGeometry(const QRect &r)
 {
-    QWidget::setFrameGeometry(QRect(r.x() - LEFT_MARGIN, r.y() - TOP_MARGIN,
-        r.width() + LEFT_MARGIN + RIGHT_MARGIN,
-        r.height() + TOP_MARGIN + BOTTOM_MARGIN));
+    QWidget::setFrameGeometry(QRect(r.x() - dimensions()[leftMargin], r.y() - dimensions()[topMargin],
+        r.width() + dimensions()[leftMargin] + dimensions()[rightMargin],
+        r.height() + dimensions()[topMargin] + dimensions()[bottomMargin]));
 }
 
 void QRadioButton::setChecked(bool isChecked)
@@ -80,5 +75,18 @@ bool QRadioButton::isChecked() const
 
 int QRadioButton::baselinePosition() const
 {
-    return height() - BASELINE_MARGIN;
+    return height() - dimensions()[baselineFudgeFactor];
+}
+
+const int *QRadioButton::dimensions() const
+{
+    // We empirically determined these dimensions.
+    // It would be better to get this info from AppKit somehow.
+    static const int w[3][7] = {
+        { 2, 4, 2, 2, 2, 14, 15 },
+        { 3, 3, 2, 2, 2, 12, 13 },
+        { 1, 2, 0, 0, 2, 10, 10 },
+    };
+    NSControl * const button = static_cast<NSControl *>(getView());
+    return w[[[button cell] controlSize]];
 }
diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index 2ee197c..fc4781c 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,16 @@
+2003-09-19  Darin Adler  <darin at apple.com>
+
+        Reviewed by Dave.
+
+        - do the prep work for the mini controls feature; Dave will finish this
+
+        * WebCoreSupport.subproj/WebFileButton.m:
+        (-[WebFileButton isFlipped]): Make this flipped, easier to understand coordinates that way.
+        (-[WebFileButton drawRect:]): Update for flipped-ness.
+        (-[WebFileButton visualFrame]): Update for flipped-ness.
+        (-[WebFileButton setVisualFrame:]): Update for flipped-ness.
+        (-[WebFileButton baseline]): Update for flipped-ness.
+
 2003-09-19  Maciej Stachowiak  <mjs at apple.com>
 
         Reviewed by Darin.
diff --git a/WebKit/WebCoreSupport.subproj/WebFileButton.m b/WebKit/WebCoreSupport.subproj/WebFileButton.m
index 451ae13..2d65720 100644
--- a/WebKit/WebCoreSupport.subproj/WebFileButton.m
+++ b/WebKit/WebCoreSupport.subproj/WebFileButton.m
@@ -77,6 +77,11 @@
     [super dealloc];
 }
 
+- (BOOL)isFlipped
+{
+    return YES;
+}
+        
 - (void)drawRect:(NSRect)rect
 {
     NSRect bounds = [self bounds];
@@ -87,9 +92,9 @@
     float left = NSMaxX([_button frame]) + AFTER_BUTTON_SPACING;
 
     if (_icon) {
-        float bottom = (bounds.size.height - BUTTON_BOTTOM_MARGIN - BUTTON_TOP_MARGIN - ICON_HEIGHT) / 2
-            + BUTTON_BOTTOM_MARGIN;
-        [_icon drawInRect:NSMakeRect(left, bottom, ICON_WIDTH, ICON_HEIGHT)
+        float top = (bounds.size.height - BUTTON_BOTTOM_MARGIN - BUTTON_TOP_MARGIN - ICON_HEIGHT) / 2
+            + BUTTON_TOP_MARGIN;
+        [_icon drawInRect:NSMakeRect(left, top, ICON_WIDTH, ICON_HEIGHT)
             fromRect:NSMakeRect(0, 0, [_icon size].width, [_icon size].height)
             operation:NSCompositeSourceOver fraction:1.0];
         left += ICON_WIDTH + ICON_FILENAME_SPACING;
@@ -97,7 +102,7 @@
 
     NSFont *font = [_button font];
     NSDictionary *attributes = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
-    [_label drawAtPoint:NSMakePoint(left, [self baseline]) withAttributes:attributes];
+    [_label drawAtPoint:NSMakePoint(left, [self baseline] - [[_button font] ascender]) withAttributes:attributes];
 
     [NSGraphicsContext restoreGraphicsState];
 }
@@ -172,7 +177,7 @@
     NSRect frame = [self frame];
     frame.origin.x += BUTTON_LEFT_MARGIN;
     frame.size.width -= BUTTON_LEFT_MARGIN;
-    frame.origin.y += BUTTON_BOTTOM_MARGIN;
+    frame.origin.y += BUTTON_TOP_MARGIN;
     frame.size.height -= BUTTON_TOP_MARGIN + BUTTON_BOTTOM_MARGIN;
     return frame;
 }
@@ -182,7 +187,7 @@
     ASSERT([self superview] == nil || [[self superview] isFlipped]);
     frame.origin.x -= BUTTON_LEFT_MARGIN;
     frame.size.width += BUTTON_LEFT_MARGIN;
-    frame.origin.y -= BUTTON_BOTTOM_MARGIN;
+    frame.origin.y -= BUTTON_TOP_MARGIN;
     frame.size.height += BUTTON_TOP_MARGIN + BUTTON_BOTTOM_MARGIN;
     [self setFrame:frame];
 }
@@ -194,8 +199,9 @@
     NSFont *buttonFont = [_button font];
     float ascender = [buttonFont ascender];
     float descender = [buttonFont descender];
-    return ([[_button cell] cellSize].height - (ascender - descender)) / 2.0
-        + BUTTON_VERTICAL_FUDGE_FACTOR + descender;
+    return -BUTTON_TOP_MARGIN
+        + ([[_button cell] cellSize].height + BUTTON_TOP_MARGIN + BUTTON_BOTTOM_MARGIN - (ascender - descender)) / 2.0
+        + ascender - BUTTON_VERTICAL_FUDGE_FACTOR;
 }
 
 - (void)beginSheet

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list