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
+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.
/* 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 */,
}
if (deselect)
deselectItems(element);
- if (fireOnChange) {
+ if (fireOnChange && m_lastOnChangeIndex != optionIndex) {
m_lastOnChangeIndex = optionIndex;
onChange();
}
#if PLATFORM(WIN)
typedef struct tagPOINT POINT;
+typedef struct tagPOINTS POINTS;
#elif PLATFORM(QT)
class QPoint;
#endif
#if PLATFORM(WIN)
IntPoint(const POINT&);
operator POINT() const;
+ IntPoint(const POINTS&);
+ operator POINTS() const;
#elif PLATFORM(QT)
IntPoint(const QPoint&);
operator QPoint() const;
+++ /dev/null
-/**
- * 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();
- }
-}
-
-}
#define POPUPMENU_H
#include "Shared.h"
+
+#include "IntRect.h"
#include <wtf/PassRefPtr.h>
#if PLATFORM(MAC)
#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);
};
}
#import "HTMLNames.h"
#import "HTMLOptGroupElement.h"
#import "HTMLOptionElement.h"
+#import "HTMLSelectElement.h"
#import "RenderMenuList.h"
#import "WebCoreSystemInterface.h"
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
}
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];
}
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;
+}
+
}