2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "ScrollbarGroup.h"
30 #include "Scrollbar.h"
31 #include "ScrollbarTheme.h"
33 #include "WebScrollbarImpl.h"
35 using namespace WebCore;
39 ScrollbarGroup::ScrollbarGroup(Page* page)
41 , m_horizontalScrollbar(0)
42 , m_verticalScrollbar(0)
44 m_page->addScrollableArea(this);
47 ScrollbarGroup::~ScrollbarGroup()
49 ASSERT(!m_horizontalScrollbar);
50 ASSERT(!m_verticalScrollbar);
52 m_page->removeScrollableArea(this);
55 void ScrollbarGroup::scrollbarCreated(WebScrollbarImpl* scrollbar)
57 if (scrollbar->scrollbar()->orientation() == HorizontalScrollbar) {
58 ASSERT(!m_horizontalScrollbar);
59 m_horizontalScrollbar = scrollbar;
60 didAddHorizontalScrollbar(scrollbar->scrollbar());
62 ASSERT(!m_verticalScrollbar);
63 m_verticalScrollbar = scrollbar;
64 didAddVerticalScrollbar(scrollbar->scrollbar());
68 void ScrollbarGroup::scrollbarDestroyed(WebScrollbarImpl* scrollbar)
70 if (scrollbar == m_horizontalScrollbar) {
71 willRemoveHorizontalScrollbar(scrollbar->scrollbar());
72 m_horizontalScrollbar = 0;
74 ASSERT(scrollbar == m_verticalScrollbar);
75 willRemoveVerticalScrollbar(scrollbar->scrollbar());
76 m_verticalScrollbar = 0;
80 void ScrollbarGroup::setLastMousePosition(const IntPoint& point)
82 m_lastMousePosition = point;
85 int ScrollbarGroup::scrollSize(WebCore::ScrollbarOrientation orientation) const
87 WebScrollbarImpl* webScrollbar = orientation == HorizontalScrollbar ? m_horizontalScrollbar : m_verticalScrollbar;
90 Scrollbar* scrollbar = webScrollbar->scrollbar();
91 return scrollbar->totalSize() - scrollbar->visibleSize();
94 int ScrollbarGroup::scrollPosition(Scrollbar* scrollbar) const
96 WebScrollbarImpl* webScrollbar = scrollbar->orientation() == HorizontalScrollbar ? m_horizontalScrollbar : m_verticalScrollbar;
99 return webScrollbar->scrollOffset();
102 void ScrollbarGroup::setScrollOffset(const IntPoint& offset)
104 if (m_horizontalScrollbar && m_horizontalScrollbar->scrollOffset() != offset.x())
105 m_horizontalScrollbar->setScrollOffset(offset.x());
106 else if (m_verticalScrollbar && m_verticalScrollbar->scrollOffset() != offset.y())
107 m_verticalScrollbar->setScrollOffset(offset.y());
110 void ScrollbarGroup::invalidateScrollbarRect(Scrollbar* scrollbar, const IntRect& rect)
112 if (m_horizontalScrollbar && scrollbar == m_horizontalScrollbar->scrollbar())
113 m_horizontalScrollbar->invalidateScrollbarRect(rect);
114 else if (m_verticalScrollbar && scrollbar == m_verticalScrollbar->scrollbar())
115 m_verticalScrollbar->invalidateScrollbarRect(rect);
118 void ScrollbarGroup::invalidateScrollCornerRect(const IntRect&)
122 bool ScrollbarGroup::isActive() const
127 ScrollableArea* ScrollbarGroup::enclosingScrollableArea() const
129 // FIXME: Return a parent scrollable area that can be scrolled.
133 bool ScrollbarGroup::isScrollCornerVisible() const
138 void ScrollbarGroup::getTickmarks(Vector<IntRect>& tickmarks) const
140 if (m_verticalScrollbar)
141 m_verticalScrollbar->getTickmarks(tickmarks);
144 IntPoint ScrollbarGroup::convertFromContainingViewToScrollbar(const Scrollbar* scrollbar, const IntPoint& parentPoint) const
146 if (m_horizontalScrollbar && scrollbar == m_horizontalScrollbar->scrollbar())
147 return m_horizontalScrollbar->convertFromContainingViewToScrollbar(parentPoint);
148 if (m_verticalScrollbar && scrollbar == m_verticalScrollbar->scrollbar())
149 return m_verticalScrollbar->convertFromContainingViewToScrollbar(parentPoint);
150 WEBKIT_ASSERT_NOT_REACHED();
154 Scrollbar* ScrollbarGroup::horizontalScrollbar() const
156 return m_horizontalScrollbar ? m_horizontalScrollbar->scrollbar() : 0;
159 Scrollbar* ScrollbarGroup::verticalScrollbar() const
161 return m_verticalScrollbar ? m_verticalScrollbar->scrollbar() : 0;
164 IntPoint ScrollbarGroup::scrollPosition() const
166 int x = m_horizontalScrollbar ? m_horizontalScrollbar->scrollOffset() : 0;
167 int y = m_verticalScrollbar ? m_verticalScrollbar->scrollOffset() : 0;
168 return IntPoint(x, y);
171 IntPoint ScrollbarGroup::minimumScrollPosition() const
176 IntPoint ScrollbarGroup::maximumScrollPosition() const
178 return IntPoint(contentsSize().width() - visibleWidth(), contentsSize().height() - visibleHeight());
181 int ScrollbarGroup::visibleHeight() const
183 if (m_verticalScrollbar)
184 return m_verticalScrollbar->scrollbar()->height();
185 if (m_horizontalScrollbar)
186 return m_horizontalScrollbar->scrollbar()->height();
187 WEBKIT_ASSERT_NOT_REACHED();
191 int ScrollbarGroup::visibleWidth() const
193 if (m_horizontalScrollbar)
194 return m_horizontalScrollbar->scrollbar()->width();
195 if (m_verticalScrollbar)
196 return m_verticalScrollbar->scrollbar()->width();
197 WEBKIT_ASSERT_NOT_REACHED();
201 IntSize ScrollbarGroup::contentsSize() const
204 if (m_horizontalScrollbar)
205 size.setWidth(m_horizontalScrollbar->scrollbar()->totalSize());
206 else if (m_verticalScrollbar) {
207 size.setWidth(m_verticalScrollbar->scrollbar()->x());
208 if (m_verticalScrollbar->scrollbar()->isOverlayScrollbar())
209 size.expand(WebScrollbar::defaultThickness(), 0);
211 if (m_verticalScrollbar)
212 size.setHeight(m_verticalScrollbar->scrollbar()->totalSize());
213 else if (m_horizontalScrollbar) {
214 size.setHeight(m_horizontalScrollbar->scrollbar()->y());
215 if (m_horizontalScrollbar->scrollbar()->isOverlayScrollbar())
216 size.expand(0, WebScrollbar::defaultThickness());
221 IntSize ScrollbarGroup::overhangAmount() const
226 IntPoint ScrollbarGroup::currentMousePosition() const
228 return m_lastMousePosition;
231 bool ScrollbarGroup::shouldSuspendScrollAnimations() const
236 void ScrollbarGroup::scrollbarStyleChanged(int, bool forceUpdate)
241 if (m_horizontalScrollbar)
242 m_horizontalScrollbar->scrollbarStyleChanged();
243 if (m_verticalScrollbar)
244 m_verticalScrollbar->scrollbarStyleChanged();
247 bool ScrollbarGroup::isOnActivePage() const
252 void ScrollbarGroup::disconnectFromPage()
257 } // namespace WebKit