diff options
author | Russell Brenner <russellbrenner@google.com> | 2010-11-18 17:33:13 -0800 |
---|---|---|
committer | Russell Brenner <russellbrenner@google.com> | 2010-12-02 13:47:21 -0800 |
commit | 6b70adc33054f8aee8c54d0f460458a9df11b8a5 (patch) | |
tree | 103a13998c33944d6ab3b8318c509a037e639460 /WebCore/platform/chromium/PopupMenuChromium.cpp | |
parent | bdf4ebc8e70b2d221b6ee7a65660918ecb1d33aa (diff) | |
download | external_webkit-6b70adc33054f8aee8c54d0f460458a9df11b8a5.zip external_webkit-6b70adc33054f8aee8c54d0f460458a9df11b8a5.tar.gz external_webkit-6b70adc33054f8aee8c54d0f460458a9df11b8a5.tar.bz2 |
Merge WebKit at r72274: Initial merge by git.
Change-Id: Ie51f0b4a16da82942bd516dce59cfb79ebbe25fb
Diffstat (limited to 'WebCore/platform/chromium/PopupMenuChromium.cpp')
-rw-r--r-- | WebCore/platform/chromium/PopupMenuChromium.cpp | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/WebCore/platform/chromium/PopupMenuChromium.cpp b/WebCore/platform/chromium/PopupMenuChromium.cpp index 3ff4ff0..04eeb93 100644 --- a/WebCore/platform/chromium/PopupMenuChromium.cpp +++ b/WebCore/platform/chromium/PopupMenuChromium.cpp @@ -1,11 +1,11 @@ /* * Copyright (c) 2008, 2009, Google Inc. All rights reserved. * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above @@ -15,7 +15,7 @@ * * Neither the name of Google Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -49,6 +49,7 @@ #include "PlatformMouseEvent.h" #include "PlatformScreen.h" #include "PlatformWheelEvent.h" +#include "PopupMenuClient.h" #include "RenderTheme.h" #include "ScrollbarTheme.h" #include "StringTruncator.h" @@ -113,7 +114,7 @@ public: // Updates our internal list to match the client. void updateFromElement(); - // Frees any allocated resources used in a particular popup session. + // Frees any allocated resources used in a particular popup session. void clear(); // Sets the index of the option that is displayed in the <select> widget in the page @@ -194,10 +195,10 @@ private: void scrollToRevealRow(int index); void scrollToRevealSelection() { scrollToRevealRow(m_selectedIndex); } - // Invalidates the row at the given index. + // Invalidates the row at the given index. void invalidateRow(int index); - // Get the bounds of a row. + // Get the bounds of a row. IntRect getRowBounds(int index); // Converts a point to an index of the row the point is over @@ -224,11 +225,11 @@ private: PopupContainerSettings m_settings; // This is the index of the item marked as "selected" - i.e. displayed in the widget on the - // page. + // page. int m_originalIndex; - // This is the index of the item that the user is hovered over or has selected using the - // keyboard in the list. They have not confirmed this selection by clicking or pressing + // This is the index of the item that the user is hovered over or has selected using the + // keyboard in the list. They have not confirmed this selection by clicking or pressing // enter yet however. int m_selectedIndex; @@ -240,7 +241,7 @@ private: // This is the number of rows visible in the popup. The maximum number visible at a time is // defined as being kMaxVisibleRows. For a scrolled popup, this can be thought of as the - // page size in data units. + // page size in data units. int m_visibleRows; // Our suggested width, not including scrollbar. @@ -538,7 +539,7 @@ ChromeClientChromium* PopupContainer::chromeClientChromium() void PopupContainer::show(const IntRect& r, FrameView* v, int index) { // The rect is the size of the select box. It's usually larger than we need. - // subtract border size so that usually the container will be displayed + // subtract border size so that usually the container will be displayed // exactly the same width as the select box. listBox()->setBaseWidth(max(r.width() - kBorderSize * 2, 0)); @@ -897,7 +898,7 @@ void PopupListBox::paintRow(GraphicsContext* gc, const IntRect& rect, int rowInd gc->fillRect(rowRect, Color::white, ColorSpaceDeviceRGB); gc->fillRect(rowRect, backColor, ColorSpaceDeviceRGB); - + if (m_popupClient->itemIsSeparator(rowIndex)) { IntRect separatorRect( rowRect.x() + separatorPadding, @@ -906,7 +907,7 @@ void PopupListBox::paintRow(GraphicsContext* gc, const IntRect& rect, int rowInd gc->fillRect(separatorRect, textColor, ColorSpaceDeviceRGB); return; } - + if (!style.isVisible()) return; @@ -991,7 +992,7 @@ void PopupListBox::paintRow(GraphicsContext* gc, const IntRect& rect, int rowInd Font PopupListBox::getRowFont(int rowIndex) { - Font itemFont = m_popupClient->menuStyle().font(); + Font itemFont = m_popupClient->itemStyle(rowIndex).font(); if (m_popupClient->itemIsLabel(rowIndex)) { // Bold-ify labels (ie, an <optgroup> heading). FontDescription d = itemFont.fontDescription(); @@ -1069,13 +1070,16 @@ void PopupListBox::selectIndex(int index) if (index < 0 || index >= numItems()) return; - if (index != m_selectedIndex && isSelectableItem(index)) { + bool isSelectable = isSelectableItem(index); + if (index != m_selectedIndex && isSelectable) { invalidateRow(m_selectedIndex); m_selectedIndex = index; invalidateRow(m_selectedIndex); scrollToRevealSelection(); m_popupClient->selectionChanged(m_selectedIndex); + } else if (!isSelectable) { + clearSelection(); } } @@ -1089,6 +1093,9 @@ int PopupListBox::getRowHeight(int index) if (index < 0) return 0; + if (m_popupClient->itemStyle(index).isDisplayNone()) + return 0; + String icon = m_popupClient->itemIcon(index); RefPtr<Image> image(Image::loadPlatformResource(icon.utf8().data())); @@ -1122,7 +1129,7 @@ void PopupListBox::scrollToRevealRow(int index) return; IntRect rowRect = getRowBounds(index); - + if (rowRect.y() < scrollY()) { // Row is above current scroll position, scroll up. ScrollView::setScrollPosition(IntPoint(0, rowRect.y())); @@ -1254,13 +1261,14 @@ void PopupListBox::layout() int paddingWidth = 0; int y = 0; for (int i = 0; i < numItems(); ++i) { - Font itemFont = getRowFont(i); - // Place the item vertically. m_items[i]->yOffset = y; - y += itemFont.height(); + if (m_popupClient->itemStyle(i).isDisplayNone()) + continue; + y += getRowHeight(i); // Ensure the popup is wide enough to fit this item. + Font itemFont = getRowFont(i); String text = m_popupClient->itemText(i); String label = m_popupClient->itemLabel(i); String icon = m_popupClient->itemIcon(i); @@ -1300,6 +1308,7 @@ void PopupListBox::layout() for (int i = 0; i < m_visibleRows; ++i) { int rowHeight = getRowHeight(i); + #if !OS(DARWIN) // Only clip the window height for non-Mac platforms. if (windowHeight + rowHeight > m_maxHeight) { @@ -1355,10 +1364,10 @@ bool PopupListBox::isPointInBounds(const IntPoint& point) /////////////////////////////////////////////////////////////////////////////// // PopupMenuChromium implementation -// -// Note: you cannot add methods to this class, since it is defined above the +// +// Note: you cannot add methods to this class, since it is defined above the // portability layer. To access methods and properties on the -// popup widgets, use |popupWindow| above. +// popup widgets, use |popupWindow| above. PopupMenuChromium::PopupMenuChromium(PopupMenuClient* client) : m_popupClient(client) |