OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 return m_scrollableArea && m_scrollableArea->isActive(); | 119 return m_scrollableArea && m_scrollableArea->isActive(); |
120 } | 120 } |
121 | 121 |
122 bool Scrollbar::isLeftSideVerticalScrollbar() const | 122 bool Scrollbar::isLeftSideVerticalScrollbar() const |
123 { | 123 { |
124 if (m_orientation == VerticalScrollbar && m_scrollableArea) | 124 if (m_orientation == VerticalScrollbar && m_scrollableArea) |
125 return m_scrollableArea->shouldPlaceVerticalScrollbarOnLeft(); | 125 return m_scrollableArea->shouldPlaceVerticalScrollbarOnLeft(); |
126 return false; | 126 return false; |
127 } | 127 } |
128 | 128 |
129 void Scrollbar::offsetDidChange() | 129 bool Scrollbar::offsetDidChange() |
130 { | 130 { |
131 ASSERT(m_scrollableArea); | 131 ASSERT(m_scrollableArea); |
132 | 132 |
133 float position = scrollableAreaCurrentPos(); | 133 float position = scrollableAreaCurrentPos(); |
134 if (position == m_currentPos) | 134 if (position == m_currentPos) |
135 return; | 135 return false; |
136 | 136 |
| 137 float oldPosition = m_currentPos; |
137 int oldThumbPosition = theme().thumbPosition(*this); | 138 int oldThumbPosition = theme().thumbPosition(*this); |
138 m_currentPos = position; | 139 m_currentPos = position; |
139 updateThumbPosition(); | 140 |
| 141 ScrollbarPart invalidParts = theme().invalidateOnThumbPositionChange( |
| 142 *this, oldPosition, position); |
| 143 if (invalidParts != NoPart) |
| 144 setNeedsPaintInvalidation(invalidParts); |
| 145 |
140 if (m_pressedPart == ThumbPart) | 146 if (m_pressedPart == ThumbPart) |
141 setPressedPos(m_pressedPos + theme().thumbPosition(*this) - oldThumbPosi
tion); | 147 setPressedPos(m_pressedPos + theme().thumbPosition(*this) - oldThumbPosi
tion); |
| 148 |
| 149 return true; |
142 } | 150 } |
143 | 151 |
144 void Scrollbar::disconnectFromScrollableArea() | 152 void Scrollbar::disconnectFromScrollableArea() |
145 { | 153 { |
146 m_scrollableArea = nullptr; | 154 m_scrollableArea = nullptr; |
147 } | 155 } |
148 | 156 |
149 void Scrollbar::setProportion(int visibleSize, int totalSize) | 157 void Scrollbar::setProportion(int visibleSize, int totalSize) |
150 { | 158 { |
151 if (visibleSize == m_visibleSize && totalSize == m_totalSize) | 159 if (visibleSize == m_visibleSize && totalSize == m_totalSize) |
152 return; | 160 return; |
153 | 161 |
154 m_visibleSize = visibleSize; | 162 m_visibleSize = visibleSize; |
155 m_totalSize = totalSize; | 163 m_totalSize = totalSize; |
156 | 164 |
157 updateThumbProportion(); | |
158 } | |
159 | |
160 void Scrollbar::updateThumb() | |
161 { | |
162 setNeedsPaintInvalidation(); | 165 setNeedsPaintInvalidation(); |
163 } | 166 } |
164 | 167 |
165 void Scrollbar::updateThumbPosition() | |
166 { | |
167 updateThumb(); | |
168 } | |
169 | |
170 void Scrollbar::updateThumbProportion() | |
171 { | |
172 updateThumb(); | |
173 } | |
174 | |
175 void Scrollbar::paint(GraphicsContext& context, const CullRect& cullRect) const | 168 void Scrollbar::paint(GraphicsContext& context, const CullRect& cullRect) const |
176 { | 169 { |
177 if (!cullRect.intersectsCullRect(frameRect())) | 170 if (!cullRect.intersectsCullRect(frameRect())) |
178 return; | 171 return; |
179 | 172 |
180 if (!theme().paint(*this, context, cullRect)) | 173 if (!theme().paint(*this, context, cullRect)) |
181 Widget::paint(context, cullRect); | 174 Widget::paint(context, cullRect); |
182 } | 175 } |
183 | 176 |
184 void Scrollbar::autoscrollTimerFired(Timer<Scrollbar>*) | 177 void Scrollbar::autoscrollTimerFired(Timer<Scrollbar>*) |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 } | 303 } |
311 | 304 |
312 void Scrollbar::setHoveredPart(ScrollbarPart part) | 305 void Scrollbar::setHoveredPart(ScrollbarPart part) |
313 { | 306 { |
314 if (part == m_hoveredPart) | 307 if (part == m_hoveredPart) |
315 return; | 308 return; |
316 | 309 |
317 if (((m_hoveredPart == NoPart || part == NoPart) && theme().invalidateOnMous
eEnterExit()) | 310 if (((m_hoveredPart == NoPart || part == NoPart) && theme().invalidateOnMous
eEnterExit()) |
318 // When there's a pressed part, we don't draw a hovered state, so there'
s no reason to invalidate. | 311 // When there's a pressed part, we don't draw a hovered state, so there'
s no reason to invalidate. |
319 || m_pressedPart == NoPart) | 312 || m_pressedPart == NoPart) |
320 setNeedsPaintInvalidation(); | 313 setNeedsPaintInvalidation(static_cast<ScrollbarPart>(m_hoveredPart | par
t)); |
321 | 314 |
322 m_hoveredPart = part; | 315 m_hoveredPart = part; |
323 } | 316 } |
324 | 317 |
325 void Scrollbar::setPressedPart(ScrollbarPart part) | 318 void Scrollbar::setPressedPart(ScrollbarPart part) |
326 { | 319 { |
327 if (m_pressedPart != NoPart | 320 if (m_pressedPart != NoPart |
328 // When we no longer have a pressed part, we can start drawing a hovered
state on the hovered part. | 321 // When we no longer have a pressed part, we can start drawing a hovered
state on the hovered part. |
329 || m_hoveredPart != NoPart) | 322 || m_hoveredPart != NoPart) |
330 setNeedsPaintInvalidation(); | 323 setNeedsPaintInvalidation(static_cast<ScrollbarPart>(m_pressedPart | m_h
overedPart | part)); |
331 m_pressedPart = part; | 324 m_pressedPart = part; |
332 } | 325 } |
333 | 326 |
334 bool Scrollbar::gestureEvent(const PlatformGestureEvent& evt) | 327 bool Scrollbar::gestureEvent(const PlatformGestureEvent& evt) |
335 { | 328 { |
336 switch (evt.type()) { | 329 switch (evt.type()) { |
337 case PlatformEvent::GestureTapDown: | 330 case PlatformEvent::GestureTapDown: |
338 setPressedPart(theme().hitTest(*this, evt.position())); | 331 setPressedPart(theme().hitTest(*this, evt.position())); |
339 m_pressedPos = orientation() == HorizontalScrollbar ? convertFromRootFra
me(evt.position()).x() : convertFromRootFrame(evt.position()).y(); | 332 m_pressedPos = orientation() == HorizontalScrollbar ? convertFromRootFra
me(evt.position()).x() : convertFromRootFrame(evt.position()).y(); |
340 return true; | 333 return true; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 { | 548 { |
556 if (!m_scrollableArea) | 549 if (!m_scrollableArea) |
557 return 0; | 550 return 0; |
558 | 551 |
559 if (m_orientation == HorizontalScrollbar) | 552 if (m_orientation == HorizontalScrollbar) |
560 return m_scrollableArea->scrollPosition().x() - m_scrollableArea->minimu
mScrollPosition().x(); | 553 return m_scrollableArea->scrollPosition().x() - m_scrollableArea->minimu
mScrollPosition().x(); |
561 | 554 |
562 return m_scrollableArea->scrollPosition().y() - m_scrollableArea->minimumScr
ollPosition().y(); | 555 return m_scrollableArea->scrollPosition().y() - m_scrollableArea->minimumScr
ollPosition().y(); |
563 } | 556 } |
564 | 557 |
565 void Scrollbar::setNeedsPaintInvalidation() | 558 void Scrollbar::setNeedsPaintInvalidation(ScrollbarPart parts) |
566 { | 559 { |
567 if (m_theme.shouldRepaintAllPartsOnInvalidation()) { | 560 if (m_theme.shouldRepaintAllPartsOnInvalidation()) |
| 561 parts = AllParts; |
| 562 if (parts & ~ThumbPart) |
568 m_trackNeedsRepaint = true; | 563 m_trackNeedsRepaint = true; |
| 564 if (parts & ThumbPart) |
569 m_thumbNeedsRepaint = true; | 565 m_thumbNeedsRepaint = true; |
570 } | |
571 if (m_scrollableArea) | 566 if (m_scrollableArea) |
572 m_scrollableArea->setScrollbarNeedsPaintInvalidation(orientation()); | 567 m_scrollableArea->setScrollbarNeedsPaintInvalidation(orientation()); |
573 } | 568 } |
574 | 569 |
575 } // namespace blink | 570 } // namespace blink |
OLD | NEW |