Reviewed by Ada.
authoraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Oct 2006 03:02:53 +0000 (03:02 +0000)
committeraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Oct 2006 03:02:53 +0000 (03:02 +0000)
        Pippity-poppity popup tweaks.

        * WebCore.xcodeproj/project.pbxproj: Removed PopupMenu.cpp from project.
        * html/HTMLSelectElement.cpp:
        (WebCore::HTMLSelectElement::setSelectedIndex): Only fire onChange if
        requested and the new index is actually different than the old one.
        * platform/IntPoint.h: Added another casting operator.
        * platform/PopupMenu.cpp: Removed. The code in here, while
        platform-independent, was only useful for the NSPopUpButtonCell
        implementation of popup menus, so I've moved it to PopupMenuMac.mm.
        * platform/PopupMenu.h: Moved the definition of PopupMenu::create into
        the header since it's fairly simple. Made some more methods private now
        that we don't have subclasses and virtual methods anymore.
        (WebCore::PopupMenu::create):
        (WebCore::PopupMenu::menuList):
        (WebCore::PopupMenu::itemHeight):
        (WebCore::PopupMenu::windowRect):
        (WebCore::PopupMenu::listIndexAtPoint):
        (WebCore::PopupMenu::focusedIndex):
        (WebCore::PopupMenu::setWasClicked):
        (WebCore::PopupMenu::wasClicked):
        (WebCore::PopupMenu::setScrollOffset):
        (WebCore::PopupMenu::scrollOffset):
        (WebCore::PopupMenu::wheelDelta):
        * platform/mac/PopupMenuMac.mm: Added the code from PopupMenu.cpp.
        (WebCore::PopupMenu::populate): Call our own clear() method to clear
        the menu.
        * platform/win/IntPointWin.cpp: New casting operator.
        (WebCore::IntPoint::IntPoint):
        (WebCore::IntPoint::operator POINTS):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@17151 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/html/HTMLSelectElement.cpp
WebCore/platform/IntPoint.h
WebCore/platform/PopupMenu.cpp [deleted file]
WebCore/platform/PopupMenu.h
WebCore/platform/mac/PopupMenuMac.mm
WebCore/platform/win/IntPointWin.cpp

index 6de9931..0bb6cf9 100644 (file)
@@ -1,5 +1,40 @@
 2006-10-19  Adam Roben  <aroben@apple.com>
 
+        Reviewed by Ada.
+
+        Pippity-poppity popup tweaks.
+
+        * WebCore.xcodeproj/project.pbxproj: Removed PopupMenu.cpp from project.
+        * html/HTMLSelectElement.cpp:
+        (WebCore::HTMLSelectElement::setSelectedIndex): Only fire onChange if
+        requested and the new index is actually different than the old one.
+        * platform/IntPoint.h: Added another casting operator.
+        * platform/PopupMenu.cpp: Removed. The code in here, while
+        platform-independent, was only useful for the NSPopUpButtonCell
+        implementation of popup menus, so I've moved it to PopupMenuMac.mm.
+        * platform/PopupMenu.h: Moved the definition of PopupMenu::create into
+        the header since it's fairly simple. Made some more methods private now
+        that we don't have subclasses and virtual methods anymore.
+        (WebCore::PopupMenu::create):
+        (WebCore::PopupMenu::menuList):
+        (WebCore::PopupMenu::itemHeight):
+        (WebCore::PopupMenu::windowRect):
+        (WebCore::PopupMenu::listIndexAtPoint):
+        (WebCore::PopupMenu::focusedIndex):
+        (WebCore::PopupMenu::setWasClicked):
+        (WebCore::PopupMenu::wasClicked):
+        (WebCore::PopupMenu::setScrollOffset):
+        (WebCore::PopupMenu::scrollOffset):
+        (WebCore::PopupMenu::wheelDelta):
+        * platform/mac/PopupMenuMac.mm: Added the code from PopupMenu.cpp.
+        (WebCore::PopupMenu::populate): Call our own clear() method to clear
+        the menu.
+        * platform/win/IntPointWin.cpp: New casting operator.
+        (WebCore::IntPoint::IntPoint):
+        (WebCore::IntPoint::operator POINTS):
+
+2006-10-19  Adam Roben  <aroben@apple.com>
+
         Reviewed by Darin.
 
         Cleaning up Document::nextFocusNode and Document::previousFocusNode.
index 3465ec4..ffcb161 100644 (file)
@@ -21,7 +21,6 @@
 /* End PBXAggregateTarget section */
 
 /* Begin PBXBuildFile section */
-               0668E18A0ADD9624004128E0 /* PopupMenu.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0668E1880ADD9624004128E0 /* PopupMenu.cpp */; };
                0668E18B0ADD9624004128E0 /* PopupMenu.h in Headers */ = {isa = PBXBuildFile; fileRef = 0668E1890ADD9624004128E0 /* PopupMenu.h */; };
                0668E1900ADD9640004128E0 /* PopupMenuMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0668E18E0ADD9640004128E0 /* PopupMenuMac.mm */; };
                066C772B0AB603B700238CC4 /* FileChooser.h in Headers */ = {isa = PBXBuildFile; fileRef = 066C772A0AB603B700238CC4 /* FileChooser.h */; };
 /* End PBXCopyFilesBuildPhase section */
 
 /* Begin PBXFileReference section */
-               0668E1880ADD9624004128E0 /* PopupMenu.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = PopupMenu.cpp; sourceTree = "<group>"; };
                0668E1890ADD9624004128E0 /* PopupMenu.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PopupMenu.h; sourceTree = "<group>"; };
                0668E18E0ADD9640004128E0 /* PopupMenuMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = PopupMenuMac.mm; sourceTree = "<group>"; };
                066C772A0AB603B700238CC4 /* FileChooser.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FileChooser.h; sourceTree = "<group>"; };
                                935C476A09AC4D4F00A6AAB4 /* PlatformWheelEvent.h */,
                                A82398A509B3ACDB00B60641 /* PlugInInfoStore.h */,
                                0668E1890ADD9624004128E0 /* PopupMenu.h */,
-                               0668E1880ADD9624004128E0 /* PopupMenu.cpp */,
                                F587852B02DE375901EA4122 /* RegularExpression.cpp */,
                                F58786B302DE3B8601EA4122 /* RegularExpression.h */,
                                6545F66C09B82FED0013006F /* ResourceLoader.cpp */,
                                656D37440ADBA5DE00A4554D /* WebNetscapePlugInStreamLoader.mm in Sources */,
                                656D37470ADBA5DE00A4554D /* WebPolicyDecider.mm in Sources */,
                                656D37490ADBA5DE00A4554D /* WebSubresourceLoader.mm in Sources */,
-                               0668E18A0ADD9624004128E0 /* PopupMenu.cpp in Sources */,
                                0668E1900ADD9640004128E0 /* PopupMenuMac.mm in Sources */,
                                6563A9A80ADF4094000ED2CD /* LoaderNSURLRequestExtras.m in Sources */,
                                14FFE31E0AE1963300136BF5 /* HTMLFrameElementBase.cpp in Sources */,
index 5ae4252..c26b0bb 100644 (file)
@@ -164,7 +164,7 @@ void HTMLSelectElement::setSelectedIndex(int optionIndex, bool deselect, bool fi
     }
     if (deselect)
         deselectItems(element);
-    if (fireOnChange) {
+    if (fireOnChange && m_lastOnChangeIndex != optionIndex) {
         m_lastOnChangeIndex = optionIndex;
         onChange();
     }
index d41e24a..f443142 100644 (file)
@@ -43,6 +43,7 @@ typedef struct _NSPoint NSPoint;
 
 #if PLATFORM(WIN)
 typedef struct tagPOINT POINT;
+typedef struct tagPOINTS POINTS;
 #elif PLATFORM(QT)
 class QPoint;
 #endif
@@ -75,6 +76,8 @@ public:
 #if PLATFORM(WIN)
     IntPoint(const POINT&);
     operator POINT() const;
+    IntPoint(const POINTS&);
+    operator POINTS() const;
 #elif PLATFORM(QT)
     IntPoint(const QPoint&);
     operator QPoint() const;
diff --git a/WebCore/platform/PopupMenu.cpp b/WebCore/platform/PopupMenu.cpp
deleted file mode 100644 (file)
index ed7396e..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- * This file is part of the popup menu implementation for <select> elements in WebCore.
- *
- * Copyright (C) 2006 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 "PopupMenu.h"
-
-#include "HTMLNames.h"
-#include "HTMLOptionElement.h"
-#include "HTMLOptGroupElement.h"
-#include "HTMLSelectElement.h"
-#include "RenderMenuList.h"
-#include <wtf/Assertions.h>
-
-namespace WebCore {
-
-using namespace HTMLNames;
-    
-PassRefPtr<PopupMenu> PopupMenu::create(RenderMenuList* menuList)
-{
-    return new PopupMenu(menuList);
-}
-
-void PopupMenu::addItems()
-{
-    ASSERT(menuList());
-    HTMLSelectElement* select = static_cast<HTMLSelectElement*>(menuList()->node());
-    if (!select)
-        return;
-    const Vector<HTMLElement*>& items = select->listItems();
-    size_t size = items.size();
-    for (size_t i = 0; i < size; ++i) {
-        HTMLElement* element = items[i];
-        if (element->hasTagName(optionTag))
-            addOption(static_cast<HTMLOptionElement*>(element));
-        else if (element->hasTagName(optgroupTag))
-            addGroupLabel(static_cast<HTMLOptGroupElement*>(element));
-        else if (element->hasTagName(hrTag))
-            addSeparator();
-        else
-            ASSERT_NOT_REACHED();
-    }
-}
-
-}
index fe3ec59..cd126b7 100644 (file)
@@ -22,6 +22,8 @@
 #define POPUPMENU_H
 
 #include "Shared.h"
+
+#include "IntRect.h"
 #include <wtf/PassRefPtr.h>
 
 #if PLATFORM(MAC)
@@ -33,64 +35,83 @@ class NSPopUpButtonCell;
 #endif
 #elif PLATFORM(WIN)
 typedef struct HWND__* HWND;
-typedef struct tagDRAWITEMSTRUCT* LPDRAWITEMSTRUCT;
+typedef struct HDC__* HDC;
+typedef struct HBITMAP__* HBITMAP;
 #endif
 
 namespace WebCore {
 
 class FrameView;
-class IntRect;
 class HTMLOptionElement;
 class HTMLOptGroupElement;
 class RenderMenuList;
 
 class PopupMenu : public Shared<PopupMenu> {
 public:
-    static PassRefPtr<PopupMenu> create(RenderMenuList* menuList);
+    static PassRefPtr<PopupMenu> create(RenderMenuList* menuList) { return new PopupMenu(menuList); }
     ~PopupMenu();
     
     void disconnectMenuList() { m_menuList = 0; }
 
-    void clear();
-    void populate();
     void show(const IntRect&, FrameView*, int index);
     void hide();
     
+    RenderMenuList* menuList() const { return m_menuList; }
+
+#if PLATFORM(WIN)
     bool up();
     bool down();
-    
-    bool wasClicked() const { return m_wasClicked; }
-    void setWasClicked(bool b = true) { m_wasClicked = b; }
 
-    int focusedIndex() const;
-    
-    RenderMenuList* menuList() { return m_menuList; }
+    int itemHeight() const { return m_itemHeight; }
+    const IntRect& windowRect() const { return m_windowRect; }
+    IntRect clientRect() const;
+
+    int listIndexAtPoint(const IntPoint& point) { return (point.y() + m_scrollOffset) / m_itemHeight; }
+    bool setFocusedIndex(int index, bool fireOnChange = false);
+    int focusedIndex() const { return m_focusedIndex; }
+
+    void paint(const IntRect& damageRect, HDC hdc = 0);
 
-#if PLATFORM(WIN)
     HWND popupHandle() const { return m_popup; }
-    void drawItem(LPDRAWITEMSTRUCT);
+
+    void setWasClicked(bool b = true) { m_wasClicked = b; }
+    bool wasClicked() const { return m_wasClicked; }
+
+    void setScrollOffset(int offset) { m_scrollOffset = offset; }
+    int scrollOffset() const { return m_scrollOffset; }
+
+    void incrementWheelDelta(int delta);
+    void reduceWheelDelta(int delta);
+    int wheelDelta() const { return m_wheelDelta; }
 #endif
 
-protected:
-    void addItems();
+private:
+    RenderMenuList* m_menuList;
+    
+#if PLATFORM(MAC)
+    void clear();
+    void populate();
     void addSeparator();
     void addGroupLabel(HTMLOptGroupElement*);
     void addOption(HTMLOptionElement*);
 
-    void setPositionAndSize(const IntRect&, FrameView*);
-    
- private:
-    PopupMenu(RenderMenuList* menuList);
-    
-    RenderMenuList* m_menuList;
-    bool m_wasClicked;
-    
-#if PLATFORM(MAC)
     RetainPtr<NSPopUpButtonCell> m_popup;
 #elif PLATFORM(WIN)
+    void calculatePositionAndSize(const IntRect&, FrameView*);
+    void invalidateItem(int index);
+
     HWND m_popup;
-    HWND m_container;
+    HDC m_DC;
+    HBITMAP m_bmp;
+    bool m_wasClicked;
+    IntRect m_windowRect;
+    int m_itemHeight;
+    int m_focusedIndex;
+    int m_scrollOffset;
+    int m_wheelDelta;
 #endif
+
+    PopupMenu(RenderMenuList* menuList);
 };
 
 }
index 7c243a2..6eee3f7 100644 (file)
@@ -26,6 +26,7 @@
 #import "HTMLNames.h"
 #import "HTMLOptGroupElement.h"
 #import "HTMLOptionElement.h"
+#import "HTMLSelectElement.h"
 #import "RenderMenuList.h"
 #import "WebCoreSystemInterface.h"
 
@@ -53,7 +54,7 @@ void PopupMenu::clear()
 void PopupMenu::populate()
 {
     if (m_popup)
-        [m_popup.get() removeAllItems];
+        clear();
     else {
         m_popup = [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:NO];
         [m_popup.get() release]; // release here since the RetainPtr has retained the object already
@@ -62,7 +63,25 @@ void PopupMenu::populate()
     }
     BOOL messagesEnabled = [[m_popup.get() menu] menuChangedMessagesEnabled];
     [[m_popup.get() menu] setMenuChangedMessagesEnabled:NO];
-    PopupMenu::addItems();
+    
+    ASSERT(menuList());
+    HTMLSelectElement* select = static_cast<HTMLSelectElement*>(menuList()->node());
+    if (!select)
+        return;
+    const Vector<HTMLElement*>& items = select->listItems();
+    size_t size = items.size();
+    for (size_t i = 0; i < size; ++i) {
+        HTMLElement* element = items[i];
+        if (element->hasTagName(optionTag))
+            addOption(static_cast<HTMLOptionElement*>(element));
+        else if (element->hasTagName(optgroupTag))
+            addGroupLabel(static_cast<HTMLOptGroupElement*>(element));
+        else if (element->hasTagName(hrTag))
+            addSeparator();
+        else
+            ASSERT_NOT_REACHED();
+    }
+    
     [[m_popup.get() menu] setMenuChangedMessagesEnabled:messagesEnabled];
 }
 
index f3f392b..a6ce0bb 100644 (file)
@@ -41,4 +41,16 @@ IntPoint::operator POINT() const
     return p;
 }
 
+IntPoint::IntPoint(const POINTS& p)
+    : m_x(p.x)
+    , m_y(p.y)
+{
+}
+
+IntPoint::operator POINTS() const
+{
+    POINTS p = {m_x, m_y};
+    return p;
+}
+
 }