Commit af490926 authored by skobes@chromium.org's avatar skobes@chromium.org

Remove FramelessScrollView.

This class was only used for rendering <select> elements.  PopupListBox now
inherits ScrollView directly.  (With future refactorings of the scrolling code
it may not even do that.)

PopupContainer now inherits Widget.  There is no need for it to be a ScrollView
since it never actually scrolls.

Review URL: https://codereview.chromium.org/562513004

git-svn-id: svn://svn.chromium.org/blink/trunk@181769 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent b5b93674
...@@ -747,9 +747,6 @@ ...@@ -747,9 +747,6 @@
'plugins/PluginListBuilder.h', 'plugins/PluginListBuilder.h',
'scheduler/Scheduler.cpp', 'scheduler/Scheduler.cpp',
'scheduler/Scheduler.h', 'scheduler/Scheduler.h',
'scroll/FramelessScrollView.cpp',
'scroll/FramelessScrollView.h',
'scroll/FramelessScrollViewClient.h',
'scroll/ProgrammaticScrollAnimator.cpp', 'scroll/ProgrammaticScrollAnimator.cpp',
'scroll/ProgrammaticScrollAnimator.h', 'scroll/ProgrammaticScrollAnimator.h',
'scroll/ScrollAnimator.cpp', 'scroll/ScrollAnimator.cpp',
......
/*
* Copyright (c) 2008, 2009, Google Inc. All rights reserved.
*
* 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
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * 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
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "platform/scroll/FramelessScrollView.h"
#include "platform/scroll/FramelessScrollViewClient.h"
namespace blink {
FramelessScrollView::~FramelessScrollView()
{
// Remove native scrollbars now before we lose the connection to the HostWindow.
setHasHorizontalScrollbar(false);
setHasVerticalScrollbar(false);
}
void FramelessScrollView::invalidateScrollbarRect(Scrollbar* scrollbar, const IntRect& rect)
{
// Add in our offset within the ScrollView.
IntRect dirtyRect = rect;
dirtyRect.move(scrollbar->x(), scrollbar->y());
invalidateRect(dirtyRect);
}
bool FramelessScrollView::isActive() const
{
// FIXME
return true;
}
bool FramelessScrollView::scrollbarsCanBeActive() const
{
return isActive();
}
IntRect FramelessScrollView::scrollableAreaBoundingBox() const
{
return windowClipRect(IncludeScrollbars);
}
void FramelessScrollView::invalidateRect(const IntRect& rect)
{
if (HostWindow* h = hostWindow())
h->invalidateContentsAndRootView(rect);
}
HostWindow* FramelessScrollView::hostWindow() const
{
return const_cast<FramelessScrollViewClient*>(m_client);
}
IntRect FramelessScrollView::windowClipRect(IncludeScrollbarsInRect scrollbarInclusion) const
{
IntRect clipRect = visibleContentRect(scrollbarInclusion);
if (shouldPlaceVerticalScrollbarOnLeft() && verticalScrollbar() && !verticalScrollbar()->isOverlayScrollbar())
clipRect.move(verticalScrollbar()->width(), 0);
return contentsToWindow(clipRect);
}
void FramelessScrollView::paintContents(GraphicsContext*, const IntRect&)
{
}
void FramelessScrollView::contentsResized()
{
}
void FramelessScrollView::scrollbarExistenceDidChange()
{
}
} // namespace blink
/*
* Copyright (c) 2008, 2009, Google Inc. All rights reserved.
*
* 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
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * 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
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef FramelessScrollView_h
#define FramelessScrollView_h
#include "platform/PlatformExport.h"
#include "platform/scroll/ScrollView.h"
namespace blink {
class FramelessScrollViewClient;
class PlatformGestureEvent;
class PlatformKeyboardEvent;
class PlatformMouseEvent;
class PlatformTouchEvent;
class PlatformWheelEvent;
// A FramelessScrollView is a ScrollView that can be used to render custom
// content, which does not have an associated LocalFrame.
//
// NOTE: It may be better to just develop a custom subclass of Widget that
// can have scroll bars for this instead of trying to reuse ScrollView.
//
class PLATFORM_EXPORT FramelessScrollView : public ScrollView {
public:
FramelessScrollView() : m_client(0) { }
virtual ~FramelessScrollView();
FramelessScrollViewClient* client() const { return m_client; }
void setClient(FramelessScrollViewClient* client) { m_client = client; }
// Event handlers that subclasses must implement.
virtual bool handleMouseDownEvent(const PlatformMouseEvent&) = 0;
virtual bool handleMouseMoveEvent(const PlatformMouseEvent&) = 0;
virtual bool handleMouseReleaseEvent(const PlatformMouseEvent&) = 0;
virtual bool handleWheelEvent(const PlatformWheelEvent&) = 0;
virtual bool handleKeyEvent(const PlatformKeyboardEvent&) = 0;
virtual bool handleTouchEvent(const PlatformTouchEvent&) = 0;
virtual bool handleGestureEvent(const PlatformGestureEvent&) = 0;
// ScrollableArea public methods:
virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&) OVERRIDE;
virtual bool isActive() const OVERRIDE;
virtual bool scrollbarsCanBeActive() const OVERRIDE;
virtual IntRect scrollableAreaBoundingBox() const OVERRIDE;
// Widget public methods:
virtual void invalidateRect(const IntRect&) OVERRIDE;
// ScrollView public methods:
virtual HostWindow* hostWindow() const OVERRIDE;
virtual IntRect windowClipRect(IncludeScrollbarsInRect = ExcludeScrollbars) const OVERRIDE;
protected:
// ScrollView protected methods:
virtual void paintContents(GraphicsContext*, const IntRect&) OVERRIDE;
virtual void contentsResized() OVERRIDE;
virtual void scrollbarExistenceDidChange() OVERRIDE;
private:
FramelessScrollViewClient* m_client;
};
} // namespace blink
#endif
...@@ -47,10 +47,10 @@ ...@@ -47,10 +47,10 @@
#include "platform/UserGestureIndicator.h" #include "platform/UserGestureIndicator.h"
#include "platform/geometry/IntRect.h" #include "platform/geometry/IntRect.h"
#include "platform/graphics/GraphicsContext.h" #include "platform/graphics/GraphicsContext.h"
#include "platform/scroll/FramelessScrollViewClient.h"
#include "public/web/WebPopupMenuInfo.h" #include "public/web/WebPopupMenuInfo.h"
#include "public/web/WebPopupType.h" #include "public/web/WebPopupType.h"
#include "public/web/WebViewClient.h" #include "public/web/WebViewClient.h"
#include "web/PopupContainerClient.h"
#include "web/WebPopupMenuImpl.h" #include "web/WebPopupMenuImpl.h"
#include "web/WebViewImpl.h" #include "web/WebViewImpl.h"
#include <limits> #include <limits>
...@@ -59,7 +59,7 @@ namespace blink { ...@@ -59,7 +59,7 @@ namespace blink {
static const int borderSize = 1; static const int borderSize = 1;
static PlatformMouseEvent constructRelativeMouseEvent(const PlatformMouseEvent& e, FramelessScrollView* parent, FramelessScrollView* child) static PlatformMouseEvent constructRelativeMouseEvent(const PlatformMouseEvent& e, PopupContainer* parent, PopupListBox* child)
{ {
IntPoint pos = parent->convertSelfToChild(child, e.position()); IntPoint pos = parent->convertSelfToChild(child, e.position());
...@@ -71,7 +71,7 @@ static PlatformMouseEvent constructRelativeMouseEvent(const PlatformMouseEvent& ...@@ -71,7 +71,7 @@ static PlatformMouseEvent constructRelativeMouseEvent(const PlatformMouseEvent&
return relativeEvent; return relativeEvent;
} }
static PlatformWheelEvent constructRelativeWheelEvent(const PlatformWheelEvent& e, FramelessScrollView* parent, FramelessScrollView* child) static PlatformWheelEvent constructRelativeWheelEvent(const PlatformWheelEvent& e, PopupContainer* parent, PopupListBox* child)
{ {
IntPoint pos = parent->convertSelfToChild(child, e.position()); IntPoint pos = parent->convertSelfToChild(child, e.position());
...@@ -90,16 +90,16 @@ PassRefPtr<PopupContainer> PopupContainer::create(PopupMenuClient* client, bool ...@@ -90,16 +90,16 @@ PassRefPtr<PopupContainer> PopupContainer::create(PopupMenuClient* client, bool
} }
PopupContainer::PopupContainer(PopupMenuClient* client, bool deviceSupportsTouch) PopupContainer::PopupContainer(PopupMenuClient* client, bool deviceSupportsTouch)
: m_listBox(PopupListBox::create(client, deviceSupportsTouch)) : m_listBox(PopupListBox::create(client, deviceSupportsTouch, this))
, m_popupOpen(false) , m_popupOpen(false)
, m_client(0)
{ {
setScrollbarModes(ScrollbarAlwaysOff, ScrollbarAlwaysOff);
} }
PopupContainer::~PopupContainer() PopupContainer::~PopupContainer()
{ {
if (m_listBox && m_listBox->parent()) if (m_listBox->parent())
removeChild(m_listBox.get()); m_listBox->setParent(0);
} }
IntRect PopupContainer::layoutAndCalculateWidgetRectInternal(IntRect widgetRectInScreen, int targetControlHeight, const FloatRect& windowRect, const FloatRect& screen, bool isRTL, const int rtlOffset, const int verticalOffset, const IntSize& transformOffset, PopupContent* listBox, bool& needToResizeView) IntRect PopupContainer::layoutAndCalculateWidgetRectInternal(IntRect widgetRectInScreen, int targetControlHeight, const FloatRect& windowRect, const FloatRect& screen, bool isRTL, const int rtlOffset, const int verticalOffset, const IntSize& transformOffset, PopupContent* listBox, bool& needToResizeView)
...@@ -212,14 +212,14 @@ IntRect PopupContainer::layoutAndCalculateWidgetRect(int targetControlHeight, co ...@@ -212,14 +212,14 @@ IntRect PopupContainer::layoutAndCalculateWidgetRect(int targetControlHeight, co
void PopupContainer::showPopup(FrameView* view) void PopupContainer::showPopup(FrameView* view)
{ {
m_frameView = view; m_frameView = view;
listBox()->m_focusedElement = m_frameView->frame().document()->focusedElement(); m_listBox->m_focusedElement = m_frameView->frame().document()->focusedElement();
IntSize transformOffset(m_controlPosition.p4().x() - m_controlPosition.p1().x(), m_controlPosition.p4().y() - m_controlPosition.p1().y() - m_controlSize.height()); IntSize transformOffset(m_controlPosition.p4().x() - m_controlPosition.p1().x(), m_controlPosition.p4().y() - m_controlPosition.p1().y() - m_controlSize.height());
popupOpened(layoutAndCalculateWidgetRect(m_controlSize.height(), transformOffset, roundedIntPoint(m_controlPosition.p4()))); popupOpened(layoutAndCalculateWidgetRect(m_controlSize.height(), transformOffset, roundedIntPoint(m_controlPosition.p4())));
m_popupOpen = true; m_popupOpen = true;
if (!m_listBox->parent()) if (!m_listBox->parent())
addChild(m_listBox.get()); m_listBox->setParent(this);
// Enable scrollbars after the listbox is inserted into the hierarchy, // Enable scrollbars after the listbox is inserted into the hierarchy,
// so it has a proper WidgetClient. // so it has a proper WidgetClient.
...@@ -232,7 +232,7 @@ void PopupContainer::showPopup(FrameView* view) ...@@ -232,7 +232,7 @@ void PopupContainer::showPopup(FrameView* view)
void PopupContainer::hidePopup() void PopupContainer::hidePopup()
{ {
listBox()->abandon(); m_listBox->abandon();
} }
void PopupContainer::notifyPopupHidden() void PopupContainer::notifyPopupHidden()
...@@ -378,9 +378,9 @@ void PopupContainer::showInRect(const FloatQuad& controlPosition, const IntSize& ...@@ -378,9 +378,9 @@ void PopupContainer::showInRect(const FloatQuad& controlPosition, const IntSize&
// The controlSize is the size of the select box. It's usually larger than // The controlSize is the size of the select box. It's usually larger than
// we need. Subtract border size so that usually the container will be // we need. Subtract border size so that usually the container will be
// displayed exactly the same width as the select box. // displayed exactly the same width as the select box.
listBox()->setBaseWidth(max(controlSize.width() - borderSize * 2, 0)); m_listBox->setBaseWidth(max(controlSize.width() - borderSize * 2, 0));
listBox()->updateFromElement(); m_listBox->updateFromElement();
// We set the selected item in updateFromElement(), and disregard the // We set the selected item in updateFromElement(), and disregard the
// index passed into this function (same as Webkit's PopupMenuWin.cpp) // index passed into this function (same as Webkit's PopupMenuWin.cpp)
...@@ -405,8 +405,8 @@ void PopupContainer::showInRect(const FloatQuad& controlPosition, const IntSize& ...@@ -405,8 +405,8 @@ void PopupContainer::showInRect(const FloatQuad& controlPosition, const IntSize&
IntRect PopupContainer::refresh(const IntRect& targetControlRect) IntRect PopupContainer::refresh(const IntRect& targetControlRect)
{ {
listBox()->setBaseWidth(max(m_controlSize.width() - borderSize * 2, 0)); m_listBox->setBaseWidth(max(m_controlSize.width() - borderSize * 2, 0));
listBox()->updateFromElement(); m_listBox->updateFromElement();
IntPoint locationInWindow = m_frameView->contentsToWindow(targetControlRect.location()); IntPoint locationInWindow = m_frameView->contentsToWindow(targetControlRect.location());
...@@ -460,7 +460,7 @@ String PopupContainer::getSelectedItemToolTip() ...@@ -460,7 +460,7 @@ String PopupContainer::getSelectedItemToolTip()
// We cannot use m_popupClient->selectedIndex() to choose tooltip message, // We cannot use m_popupClient->selectedIndex() to choose tooltip message,
// because the selectedIndex() might return final selected index, not // because the selectedIndex() might return final selected index, not
// hovering selection. // hovering selection.
return listBox()->m_popupClient->itemToolTip(listBox()->m_selectedIndex); return m_listBox->m_popupClient->itemToolTip(m_listBox->m_selectedIndex);
} }
void PopupContainer::popupOpened(const IntRect& bounds) void PopupContainer::popupOpened(const IntRect& bounds)
...@@ -514,4 +514,15 @@ void PopupContainer::getPopupMenuInfo(WebPopupMenuInfo* info) ...@@ -514,4 +514,15 @@ void PopupContainer::getPopupMenuInfo(WebPopupMenuInfo* info)
info->rightAligned = menuStyle().textDirection() == RTL; info->rightAligned = menuStyle().textDirection() == RTL;
} }
void PopupContainer::invalidateRect(const IntRect& rect)
{
if (HostWindow* h = hostWindow())
h->invalidateContentsAndRootView(rect);
}
HostWindow* PopupContainer::hostWindow() const
{
return const_cast<PopupContainerClient*>(m_client);
}
} // namespace blink } // namespace blink
...@@ -34,36 +34,45 @@ ...@@ -34,36 +34,45 @@
#include "platform/PopupMenuStyle.h" #include "platform/PopupMenuStyle.h"
#include "platform/geometry/FloatQuad.h" #include "platform/geometry/FloatQuad.h"
#include "platform/scroll/FramelessScrollView.h"
#include "web/PopupListBox.h" #include "web/PopupListBox.h"
namespace blink { namespace blink {
class ChromeClient; class ChromeClient;
class FrameView; class FrameView;
class PopupContainerClient;
class PopupMenuClient; class PopupMenuClient;
struct WebPopupMenuInfo; struct WebPopupMenuInfo;
class PopupContainer FINAL : public FramelessScrollView { // This class wraps a PopupListBox. It positions the popup, paints the border
// around it, and forwards input events.
// FIXME(skobes): This class can probably be combined with PopupListBox.
class PopupContainer FINAL : public Widget {
public: public:
static PassRefPtr<PopupContainer> create(PopupMenuClient*, bool deviceSupportsTouch); static PassRefPtr<PopupContainer> create(PopupMenuClient*, bool deviceSupportsTouch);
// Whether a key event should be sent to this popup. // Whether a key event should be sent to this popup.
bool isInterestedInEventForKey(int keyCode); bool isInterestedInEventForKey(int keyCode);
// FramelessScrollView // Widget
virtual void paint(GraphicsContext*, const IntRect&) OVERRIDE; virtual void paint(GraphicsContext*, const IntRect&) OVERRIDE;
virtual void hide() OVERRIDE; virtual void hide() OVERRIDE;
virtual bool handleMouseDownEvent(const PlatformMouseEvent&) OVERRIDE; virtual HostWindow* hostWindow() const OVERRIDE;
virtual bool handleMouseMoveEvent(const PlatformMouseEvent&) OVERRIDE; virtual void invalidateRect(const IntRect&) OVERRIDE;
virtual bool handleMouseReleaseEvent(const PlatformMouseEvent&) OVERRIDE;
virtual bool handleWheelEvent(const PlatformWheelEvent&) OVERRIDE;
virtual bool handleKeyEvent(const PlatformKeyboardEvent&) OVERRIDE;
virtual bool handleTouchEvent(const PlatformTouchEvent&) OVERRIDE;
virtual bool handleGestureEvent(const PlatformGestureEvent&) OVERRIDE;
// PopupContainer methods // PopupContainer methods
bool handleMouseDownEvent(const PlatformMouseEvent&);
bool handleMouseMoveEvent(const PlatformMouseEvent&);
bool handleMouseReleaseEvent(const PlatformMouseEvent&);
bool handleWheelEvent(const PlatformWheelEvent&);
bool handleKeyEvent(const PlatformKeyboardEvent&);
bool handleTouchEvent(const PlatformTouchEvent&);
bool handleGestureEvent(const PlatformGestureEvent&);
PopupContainerClient* client() const { return m_client; }
void setClient(PopupContainerClient* client) { m_client = client; }
// Show the popup // Show the popup
void showPopup(FrameView*); void showPopup(FrameView*);
...@@ -109,6 +118,10 @@ public: ...@@ -109,6 +118,10 @@ public:
// This is public for testing. // This is public for testing.
static IntRect layoutAndCalculateWidgetRectInternal(IntRect widgetRectInScreen, int targetControlHeight, const FloatRect& windowRect, const FloatRect& screen, bool isRTL, const int rtlOffset, const int verticalOffset, const IntSize& transformOffset, PopupContent*, bool& needToResizeView); static IntRect layoutAndCalculateWidgetRectInternal(IntRect widgetRectInScreen, int targetControlHeight, const FloatRect& windowRect, const FloatRect& screen, bool isRTL, const int rtlOffset, const int verticalOffset, const IntSize& transformOffset, PopupContent*, bool& needToResizeView);
void disconnectClient() { m_listBox->disconnectClient(); }
void updateFromElement() { m_listBox->updateFromElement(); }
private: private:
friend class WTF::RefCounted<PopupContainer>; friend class WTF::RefCounted<PopupContainer>;
...@@ -149,6 +162,8 @@ private: ...@@ -149,6 +162,8 @@ private:
// Whether the popup is currently open. // Whether the popup is currently open.
bool m_popupOpen; bool m_popupOpen;
PopupContainerClient* m_client;
}; };
} // namespace blink } // namespace blink
......
...@@ -28,18 +28,17 @@ ...@@ -28,18 +28,17 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef FramelessScrollViewClient_h #ifndef PopupContainerClient_h
#define FramelessScrollViewClient_h #define PopupContainerClient_h
#include "platform/HostWindow.h" #include "platform/HostWindow.h"
#include "platform/PlatformExport.h" #include "web/PopupContainer.h"
namespace blink { namespace blink {
class FramelessScrollView;
class PLATFORM_EXPORT FramelessScrollViewClient : public HostWindow { class PopupContainerClient : public HostWindow {
public: public:
virtual void popupClosed(FramelessScrollView*) = 0; virtual void popupClosed(PopupContainer*) = 0;
}; };
} // namespace blink } // namespace blink
......
...@@ -47,11 +47,11 @@ ...@@ -47,11 +47,11 @@
#include "platform/fonts/FontSelector.h" #include "platform/fonts/FontSelector.h"
#include "platform/geometry/IntRect.h" #include "platform/geometry/IntRect.h"
#include "platform/graphics/GraphicsContext.h" #include "platform/graphics/GraphicsContext.h"
#include "platform/scroll/FramelessScrollViewClient.h"
#include "platform/scroll/ScrollbarTheme.h" #include "platform/scroll/ScrollbarTheme.h"
#include "platform/text/StringTruncator.h" #include "platform/text/StringTruncator.h"
#include "platform/text/TextRun.h" #include "platform/text/TextRun.h"
#include "web/PopupContainer.h" #include "web/PopupContainer.h"
#include "web/PopupContainerClient.h"
#include "web/PopupMenuChromium.h" #include "web/PopupMenuChromium.h"
#include "wtf/ASCIICType.h" #include "wtf/ASCIICType.h"
#include "wtf/CurrentTime.h" #include "wtf/CurrentTime.h"
...@@ -66,7 +66,7 @@ static const int maxVisibleRows = 20; ...@@ -66,7 +66,7 @@ static const int maxVisibleRows = 20;
static const int minEndOfLinePadding = 2; static const int minEndOfLinePadding = 2;
static const TimeStamp typeAheadTimeoutMs = 1000; static const TimeStamp typeAheadTimeoutMs = 1000;
PopupListBox::PopupListBox(PopupMenuClient* client, bool deviceSupportsTouch) PopupListBox::PopupListBox(PopupMenuClient* client, bool deviceSupportsTouch, PopupContainer* container)
: m_deviceSupportsTouch(deviceSupportsTouch) : m_deviceSupportsTouch(deviceSupportsTouch)
, m_originalIndex(0) , m_originalIndex(0)
, m_selectedIndex(0) , m_selectedIndex(0)
...@@ -78,10 +78,19 @@ PopupListBox::PopupListBox(PopupMenuClient* client, bool deviceSupportsTouch) ...@@ -78,10 +78,19 @@ PopupListBox::PopupListBox(PopupMenuClient* client, bool deviceSupportsTouch)
, m_repeatingChar(0) , m_repeatingChar(0)
, m_lastCharTime(0) , m_lastCharTime(0)
, m_maxWindowWidth(std::numeric_limits<int>::max()) , m_maxWindowWidth(std::numeric_limits<int>::max())
, m_container(container)
{ {
setScrollbarModes(ScrollbarAlwaysOff, ScrollbarAlwaysOff); setScrollbarModes(ScrollbarAlwaysOff, ScrollbarAlwaysOff);
} }
PopupListBox::~PopupListBox()
{
clear();
setHasHorizontalScrollbar(false);
setHasVerticalScrollbar(false);
}
bool PopupListBox::handleMouseDownEvent(const PlatformMouseEvent& event) bool PopupListBox::handleMouseDownEvent(const PlatformMouseEvent& event)
{ {
Scrollbar* scrollbar = scrollbarAtPoint(event.position()); Scrollbar* scrollbar = scrollbarAtPoint(event.position());
...@@ -467,7 +476,7 @@ void PopupListBox::paintRow(GraphicsContext* gc, const IntRect& rect, int rowInd ...@@ -467,7 +476,7 @@ void PopupListBox::paintRow(GraphicsContext* gc, const IntRect& rect, int rowInd
gc->drawBidiText(itemFont, textRunPaintInfo, IntPoint(textX, textY)); gc->drawBidiText(itemFont, textRunPaintInfo, IntPoint(textX, textY));
} }
Font PopupListBox::getRowFont(int rowIndex) Font PopupListBox::getRowFont(int rowIndex) const
{ {
Font itemFont = m_popupClient->itemStyle(rowIndex).font(); Font itemFont = m_popupClient->itemStyle(rowIndex).font();
if (m_popupClient->itemIsLabel(rowIndex)) { if (m_popupClient->itemIsLabel(rowIndex)) {
...@@ -568,7 +577,7 @@ void PopupListBox::setOriginalIndex(int index) ...@@ -568,7 +577,7 @@ void PopupListBox::setOriginalIndex(int index)
m_originalIndex = m_selectedIndex = index; m_originalIndex = m_selectedIndex = index;
} }
int PopupListBox::getRowHeight(int index) int PopupListBox::getRowHeight(int index) const
{ {
int minimumHeight = m_deviceSupportsTouch ? optionRowHeightForTouch : minRowHeight; int minimumHeight = m_deviceSupportsTouch ? optionRowHeightForTouch : minRowHeight;
...@@ -596,8 +605,7 @@ void PopupListBox::invalidateRow(int index) ...@@ -596,8 +605,7 @@ void PopupListBox::invalidateRow(int index)
if (index < 0) if (index < 0)
return; return;
// Invalidate in the window contents, as FramelessScrollView::invalidateRect // Invalidate in the window contents, as invalidateRect paints in the window coordinates.
// paints in the window coordinates.
IntRect clipRect = contentsToWindow(getRowBounds(index)); IntRect clipRect = contentsToWindow(getRowBounds(index));
if (shouldPlaceVerticalScrollbarOnLeft() && verticalScrollbar() && !verticalScrollbar()->isOverlayScrollbar()) if (shouldPlaceVerticalScrollbarOnLeft() && verticalScrollbar() && !verticalScrollbar()->isOverlayScrollbar())
clipRect.move(verticalScrollbar()->width(), 0); clipRect.move(verticalScrollbar()->width(), 0);
...@@ -683,10 +691,9 @@ void PopupListBox::adjustSelectedIndex(int delta) ...@@ -683,10 +691,9 @@ void PopupListBox::adjustSelectedIndex(int delta)
void PopupListBox::hidePopup() void PopupListBox::hidePopup()
{ {
if (parent()) { if (parent()) {
PopupContainer* container = static_cast<PopupContainer*>(parent()); if (m_container->client())
if (container->client()) m_container->client()->popupClosed(m_container);
container->client()->popupClosed(container); m_container->notifyPopupHidden();
container->notifyPopupHidden();
} }
if (m_popupClient) if (m_popupClient)
...@@ -834,4 +841,42 @@ int PopupListBox::popupContentHeight() const ...@@ -834,4 +841,42 @@ int PopupListBox::popupContentHeight() const
return height(); return height();
} }
void PopupListBox::invalidateRect(const IntRect& rect)
{
if (HostWindow* h = hostWindow())
h->invalidateContentsAndRootView(rect);
}
IntRect PopupListBox::windowClipRect(IncludeScrollbarsInRect scrollbarInclusion) const
{
IntRect clipRect = visibleContentRect(scrollbarInclusion);
if (shouldPlaceVerticalScrollbarOnLeft() && verticalScrollbar() && !verticalScrollbar()->isOverlayScrollbar())
clipRect.move(verticalScrollbar()->width(), 0);
return contentsToWindow(clipRect);
}
void PopupListBox::invalidateScrollbarRect(Scrollbar* scrollbar, const IntRect& rect)
{
// Add in our offset within the ScrollView.
IntRect dirtyRect = rect;
dirtyRect.move(scrollbar->x(), scrollbar->y());
invalidateRect(dirtyRect);
}
bool PopupListBox::isActive() const
{
// FIXME
return true;
}
bool PopupListBox::scrollbarsCanBeActive() const
{
return isActive();
}
IntRect PopupListBox::scrollableAreaBoundingBox() const
{
return windowClipRect(IncludeScrollbars);
}
} // namespace blink } // namespace blink
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#define PopupListBox_h #define PopupListBox_h
#include "core/dom/Element.h" #include "core/dom/Element.h"
#include "platform/scroll/FramelessScrollView.h" #include "platform/scroll/ScrollView.h"
#include "platform/text/TextDirection.h" #include "platform/text/TextDirection.h"
#include "wtf/text/WTFString.h" #include "wtf/text/WTFString.h"
...@@ -46,6 +46,7 @@ class PlatformMouseEvent; ...@@ -46,6 +46,7 @@ class PlatformMouseEvent;
class PlatformGestureEvent; class PlatformGestureEvent;
class PlatformTouchEvent; class PlatformTouchEvent;
class PlatformWheelEvent; class PlatformWheelEvent;
class PopupContainer;
class PopupMenuClient; class PopupMenuClient;
typedef unsigned long long TimeStamp; typedef unsigned long long TimeStamp;
...@@ -82,31 +83,39 @@ struct PopupItem { ...@@ -82,31 +83,39 @@ struct PopupItem {
bool displayNone; bool displayNone;
}; };
// This class uses WebCore code to paint and handle events for a drop-down list // This class manages the scrollable content inside a <select> popup.
// box ("combobox" on Windows). class PopupListBox FINAL : public ScrollView, public PopupContent {
class PopupListBox FINAL : public FramelessScrollView, public PopupContent {
public: public:
static PassRefPtr<PopupListBox> create(PopupMenuClient* client, bool deviceSupportsTouch) static PassRefPtr<PopupListBox> create(PopupMenuClient* client, bool deviceSupportsTouch, PopupContainer* container)
{ {
return adoptRef(new PopupListBox(client, deviceSupportsTouch)); return adoptRef(new PopupListBox(client, deviceSupportsTouch, container));
} }
// FramelessScrollView // Widget
virtual void paint(GraphicsContext*, const IntRect&) OVERRIDE; virtual void invalidateRect(const IntRect&) OVERRIDE;
virtual bool handleMouseDownEvent(const PlatformMouseEvent&) OVERRIDE;
virtual bool handleMouseMoveEvent(const PlatformMouseEvent&) OVERRIDE; // ScrollableArea
virtual bool handleMouseReleaseEvent(const PlatformMouseEvent&) OVERRIDE; virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&) OVERRIDE;
virtual bool handleWheelEvent(const PlatformWheelEvent&) OVERRIDE; virtual bool isActive() const OVERRIDE;
virtual bool handleKeyEvent(const PlatformKeyboardEvent&) OVERRIDE; virtual bool scrollbarsCanBeActive() const OVERRIDE;
virtual bool handleTouchEvent(const PlatformTouchEvent&) OVERRIDE; virtual IntRect scrollableAreaBoundingBox() const OVERRIDE;
virtual bool handleGestureEvent(const PlatformGestureEvent&) OVERRIDE;
// ScrollView // ScrollView
virtual void paint(GraphicsContext*, const IntRect&) OVERRIDE;
virtual HostWindow* hostWindow() const OVERRIDE; virtual HostWindow* hostWindow() const OVERRIDE;
virtual bool shouldPlaceVerticalScrollbarOnLeft() const OVERRIDE; virtual bool shouldPlaceVerticalScrollbarOnLeft() const OVERRIDE;
virtual IntRect windowClipRect(IncludeScrollbarsInRect = ExcludeScrollbars) const OVERRIDE;
// PopupListBox methods // PopupListBox methods
virtual bool handleMouseDownEvent(const PlatformMouseEvent&);
virtual bool handleMouseMoveEvent(const PlatformMouseEvent&);
virtual bool handleMouseReleaseEvent(const PlatformMouseEvent&);
virtual bool handleWheelEvent(const PlatformWheelEvent&);
virtual bool handleKeyEvent(const PlatformKeyboardEvent&);
virtual bool handleTouchEvent(const PlatformTouchEvent&);
virtual bool handleGestureEvent(const PlatformGestureEvent&);
// Closes the popup // Closes the popup
void abandon(); void abandon();
...@@ -141,7 +150,7 @@ public: ...@@ -141,7 +150,7 @@ public:
bool isInterestedInEventForKey(int keyCode); bool isInterestedInEventForKey(int keyCode);
// Gets the height of a row. // Gets the height of a row.
int getRowHeight(int index); int getRowHeight(int index) const;
int getRowBaseWidth(int index); int getRowBaseWidth(int index);
...@@ -159,16 +168,17 @@ public: ...@@ -159,16 +168,17 @@ public:
static const int defaultMaxHeight; static const int defaultMaxHeight;
protected:
// ScrollView
virtual void paintContents(GraphicsContext*, const IntRect&) OVERRIDE { }
virtual void scrollbarExistenceDidChange() OVERRIDE { }
private: private:
friend class PopupContainer; friend class PopupContainer;
friend class RefCounted<PopupListBox>; friend class RefCounted<PopupListBox>;
PopupListBox(PopupMenuClient*, bool deviceSupportsTouch); PopupListBox(PopupMenuClient*, bool deviceSupportsTouch, PopupContainer*);
virtual ~PopupListBox();
virtual ~PopupListBox()
{
clear();
}
// Hides the popup. Other classes should not call this. Use abandon instead. // Hides the popup. Other classes should not call this. Use abandon instead.
void hidePopup(); void hidePopup();
...@@ -211,7 +221,7 @@ private: ...@@ -211,7 +221,7 @@ private:
void typeAheadFind(const PlatformKeyboardEvent&); void typeAheadFind(const PlatformKeyboardEvent&);
// Returns the font to use for the given row // Returns the font to use for the given row
Font getRowFont(int index); Font getRowFont(int index) const;
// Moves the selection down/up one item, taking care of looping back to the // Moves the selection down/up one item, taking care of looping back to the
// first/last element if m_loopSelectionNavigation is true. // first/last element if m_loopSelectionNavigation is true.
...@@ -275,6 +285,8 @@ private: ...@@ -275,6 +285,8 @@ private:
// To forward last mouse release event. // To forward last mouse release event.
RefPtrWillBePersistent<Element> m_focusedElement; RefPtrWillBePersistent<Element> m_focusedElement;
PopupContainer* m_container;
}; };
} // namespace blink } // namespace blink
......
...@@ -49,7 +49,7 @@ PopupMenuChromium::~PopupMenuChromium() ...@@ -49,7 +49,7 @@ PopupMenuChromium::~PopupMenuChromium()
{ {
// When the PopupMenuChromium is destroyed, the client could already have been deleted. // When the PopupMenuChromium is destroyed, the client could already have been deleted.
if (m_popup) if (m_popup)
m_popup->listBox()->disconnectClient(); m_popup->disconnectClient();
hide(); hide();
} }
...@@ -70,7 +70,7 @@ void PopupMenuChromium::hide() ...@@ -70,7 +70,7 @@ void PopupMenuChromium::hide()
void PopupMenuChromium::updateFromElement() void PopupMenuChromium::updateFromElement()
{ {
m_popup->listBox()->updateFromElement(); m_popup->updateFromElement();
} }
......
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
#include "platform/geometry/IntRect.h" #include "platform/geometry/IntRect.h"
#include "platform/graphics/GraphicsContext.h" #include "platform/graphics/GraphicsContext.h"
#include "platform/graphics/skia/SkiaUtils.h" #include "platform/graphics/skia/SkiaUtils.h"
#include "platform/scroll/FramelessScrollView.h"
#include "public/platform/Platform.h" #include "public/platform/Platform.h"
#include "public/platform/WebCompositorSupport.h" #include "public/platform/WebCompositorSupport.h"
#include "public/platform/WebContentLayer.h" #include "public/platform/WebContentLayer.h"
...@@ -89,7 +88,7 @@ void WebPopupMenuImpl::willCloseLayerTreeView() ...@@ -89,7 +88,7 @@ void WebPopupMenuImpl::willCloseLayerTreeView()
m_layerTreeView = 0; m_layerTreeView = 0;
} }
void WebPopupMenuImpl::initialize(FramelessScrollView* widget, const WebRect& bounds) void WebPopupMenuImpl::initialize(PopupContainer* widget, const WebRect& bounds)
{ {
m_widget = widget; m_widget = widget;
m_widget->setClient(this); m_widget->setClient(this);
...@@ -397,10 +396,7 @@ WebScreenInfo WebPopupMenuImpl::screenInfo() const ...@@ -397,10 +396,7 @@ WebScreenInfo WebPopupMenuImpl::screenInfo() const
return WebScreenInfo(); return WebScreenInfo();
} }
//----------------------------------------------------------------------------- void WebPopupMenuImpl::popupClosed(PopupContainer* widget)
// FramelessScrollViewClient
void WebPopupMenuImpl::popupClosed(FramelessScrollView* widget)
{ {
ASSERT(widget == m_widget); ASSERT(widget == m_widget);
if (m_widget) { if (m_widget) {
......
...@@ -31,17 +31,16 @@ ...@@ -31,17 +31,16 @@
#ifndef WebPopupMenuImpl_h #ifndef WebPopupMenuImpl_h
#define WebPopupMenuImpl_h #define WebPopupMenuImpl_h
#include "platform/scroll/FramelessScrollViewClient.h"
#include "public/platform/WebContentLayerClient.h" #include "public/platform/WebContentLayerClient.h"
#include "public/platform/WebPoint.h" #include "public/platform/WebPoint.h"
#include "public/platform/WebSize.h" #include "public/platform/WebSize.h"
#include "public/web/WebPopupMenu.h" #include "public/web/WebPopupMenu.h"
#include "web/PopupContainerClient.h"
#include "wtf/OwnPtr.h" #include "wtf/OwnPtr.h"
#include "wtf/RefCounted.h" #include "wtf/RefCounted.h"
namespace blink { namespace blink {
class LocalFrame; class LocalFrame;
class FramelessScrollView;
class KeyboardEvent; class KeyboardEvent;
class Page; class Page;
class PlatformKeyboardEvent; class PlatformKeyboardEvent;
...@@ -57,7 +56,7 @@ class WebTouchEvent; ...@@ -57,7 +56,7 @@ class WebTouchEvent;
class Widget; class Widget;
struct WebRect; struct WebRect;
class WebPopupMenuImpl : public WebPopupMenu, public FramelessScrollViewClient, public WebContentLayerClient, public RefCounted<WebPopupMenuImpl> { class WebPopupMenuImpl : public WebPopupMenu, public PopupContainerClient, public WebContentLayerClient, public RefCounted<WebPopupMenuImpl> {
WTF_MAKE_FAST_ALLOCATED; WTF_MAKE_FAST_ALLOCATED;
public: public:
// WebWidget functions: // WebWidget functions:
...@@ -92,7 +91,7 @@ public: ...@@ -92,7 +91,7 @@ public:
WebContentLayerClient::GraphicsContextStatus = GraphicsContextEnabled) OVERRIDE FINAL; WebContentLayerClient::GraphicsContextStatus = GraphicsContextEnabled) OVERRIDE FINAL;
// WebPopupMenuImpl // WebPopupMenuImpl
void initialize(FramelessScrollView* widget, const WebRect& bounds); void initialize(PopupContainer* widget, const WebRect& bounds);
WebWidgetClient* client() { return m_client; } WebWidgetClient* client() { return m_client; }
...@@ -120,8 +119,8 @@ public: ...@@ -120,8 +119,8 @@ public:
virtual IntRect rootViewToScreen(const IntRect&) const OVERRIDE FINAL; virtual IntRect rootViewToScreen(const IntRect&) const OVERRIDE FINAL;
virtual WebScreenInfo screenInfo() const OVERRIDE FINAL; virtual WebScreenInfo screenInfo() const OVERRIDE FINAL;
// FramelessScrollViewClient methods: // PopupContainerClient methods:
virtual void popupClosed(FramelessScrollView*) OVERRIDE FINAL; virtual void popupClosed(PopupContainer*) OVERRIDE FINAL;
WebWidgetClient* m_client; WebWidgetClient* m_client;
WebSize m_size; WebSize m_size;
...@@ -133,13 +132,13 @@ public: ...@@ -133,13 +132,13 @@ public:
// This is a non-owning ref. The popup will notify us via popupClosed() // This is a non-owning ref. The popup will notify us via popupClosed()
// before it is destroyed. // before it is destroyed.
FramelessScrollView* m_widget; PopupContainer* m_widget;
}; };
DEFINE_TYPE_CASTS(WebPopupMenuImpl, WebWidget, widget, widget->isPopupMenu(), widget.isPopupMenu()); DEFINE_TYPE_CASTS(WebPopupMenuImpl, WebWidget, widget, widget->isPopupMenu(), widget.isPopupMenu());
// WebPopupMenuImpl is the only implementation of FramelessScrollViewClient, so // WebPopupMenuImpl is the only implementation of PopupContainerClient, so
// no need for further checking. // no need for further checking.
DEFINE_TYPE_CASTS(WebPopupMenuImpl, FramelessScrollViewClient, client, true, true); DEFINE_TYPE_CASTS(WebPopupMenuImpl, PopupContainerClient, client, true, true);
} // namespace blink } // namespace blink
......
...@@ -71,6 +71,7 @@ ...@@ -71,6 +71,7 @@
'PageWidgetDelegate.h', 'PageWidgetDelegate.h',
'PopupContainer.cpp', 'PopupContainer.cpp',
'PopupContainer.h', 'PopupContainer.h',
'PopupContainerClient.h',
'PopupListBox.cpp', 'PopupListBox.cpp',
'PopupListBox.h', 'PopupListBox.h',
'PopupMenuChromium.cpp', 'PopupMenuChromium.cpp',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment