OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google 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 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "platform/scroll/ScrollbarThemeClient.h" | 31 #include "platform/scroll/ScrollbarThemeClient.h" |
32 #include "platform/transforms/TransformationMatrix.h" | 32 #include "platform/transforms/TransformationMatrix.h" |
33 #include "public/platform/Platform.h" | 33 #include "public/platform/Platform.h" |
34 #include "public/platform/WebRect.h" | 34 #include "public/platform/WebRect.h" |
35 #include "public/platform/WebThemeEngine.h" | 35 #include "public/platform/WebThemeEngine.h" |
36 | 36 |
37 #include <algorithm> | 37 #include <algorithm> |
38 | 38 |
39 using namespace std; | 39 using namespace std; |
40 | 40 |
| 41 namespace { |
| 42 |
| 43 const int kDefaultOverlayScrollbarMinThumbThickness = 9; |
| 44 |
| 45 } // namespace |
| 46 |
41 namespace WebCore { | 47 namespace WebCore { |
42 | 48 |
43 ScrollbarThemeOverlay::ScrollbarThemeOverlay(int thumbThickness, int scrollbarMa
rgin, HitTestBehavior allowHitTest, Color color) | 49 ScrollbarThemeOverlay::ScrollbarThemeOverlay(int thumbThickness, int scrollbarMa
rgin, HitTestBehavior allowHitTest, Color color) |
44 : ScrollbarTheme() | 50 : ScrollbarTheme() |
45 , m_thumbThickness(thumbThickness) | 51 , m_thumbThickness(thumbThickness) |
46 , m_scrollbarMargin(scrollbarMargin) | 52 , m_scrollbarMargin(scrollbarMargin) |
47 , m_allowHitTest(allowHitTest) | 53 , m_allowHitTest(allowHitTest) |
48 , m_color(color) | 54 , m_color(color) |
49 , m_useSolidColor(true) | 55 , m_useSolidColor(true) |
50 { | 56 { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 thumbRect.setWidth(thumbRect.width() - m_scrollbarMargin); | 139 thumbRect.setWidth(thumbRect.width() - m_scrollbarMargin); |
134 if (scrollbar->isLeftSideVerticalScrollbar()) | 140 if (scrollbar->isLeftSideVerticalScrollbar()) |
135 thumbRect.setX(thumbRect.x() + m_scrollbarMargin); | 141 thumbRect.setX(thumbRect.x() + m_scrollbarMargin); |
136 } | 142 } |
137 | 143 |
138 if (m_useSolidColor) { | 144 if (m_useSolidColor) { |
139 context->fillRect(thumbRect, m_color); | 145 context->fillRect(thumbRect, m_color); |
140 return; | 146 return; |
141 } | 147 } |
142 | 148 |
143 blink::WebThemeEngine::State state = blink::WebThemeEngine::StateNormal; | |
144 if (scrollbar->pressedPart() == ThumbPart) | |
145 state = blink::WebThemeEngine::StatePressed; | |
146 else if (scrollbar->hoveredPart() == ThumbPart) | |
147 state = blink::WebThemeEngine::StateHover; | |
148 | |
149 blink::WebCanvas* canvas = context->canvas(); | 149 blink::WebCanvas* canvas = context->canvas(); |
150 | 150 |
151 blink::WebThemeEngine::Part part = blink::WebThemeEngine::PartScrollbarHoriz
ontalThumb; | 151 blink::WebThemeEngine::Part part = blink::WebThemeEngine::PartScrollbarHoriz
ontalThumb; |
152 if (scrollbar->orientation() == VerticalScrollbar) | 152 if (scrollbar->orientation() == VerticalScrollbar) |
153 part = blink::WebThemeEngine::PartScrollbarVerticalThumb; | 153 part = blink::WebThemeEngine::PartScrollbarVerticalThumb; |
154 | 154 |
155 blink::Platform::current()->themeEngine()->paint(canvas, part, state, blink:
:WebRect(rect), 0); | 155 if (scrollbar->isDuringStateTransitionAnimation()) { |
| 156 // Paint in between of two states. First get information from ScrollAnim
ator |
| 157 double progress = scrollbar->stateTransitionProgress(); |
| 158 blink::WebThemeEngine::State startState = scrollbar->stateTransitionStar
tState(); |
| 159 blink::WebThemeEngine::State endState = scrollbar->stateTransitionEndSta
te(); |
| 160 double thumbThicknessChanged = progress * (m_thumbThickness - kDefaultOv
erlayScrollbarMinThumbThickness); |
| 161 double disThumbThickness = m_thumbThickness - thumbThicknessChanged; |
| 162 int displayedThumbThickness = static_cast<int>(disThumbThickness); |
| 163 if (startState == blink::WebThemeEngine::StateNormal) |
| 164 displayedThumbThickness = kDefaultOverlayScrollbarMinThumbThickness
+ thumbThicknessChanged; |
| 165 |
| 166 if (scrollbar->orientation() == HorizontalScrollbar) { |
| 167 thumbRect.setY(thumbRect.y() + (m_thumbThickness - displayedThumbThi
ckness)); |
| 168 thumbRect.setHeight(displayedThumbThickness); |
| 169 } else { |
| 170 thumbRect.setWidth(displayedThumbThickness); |
| 171 if (!scrollbar->isLeftSideVerticalScrollbar()) |
| 172 thumbRect.setX(thumbRect.x() + (m_thumbThickness - displayedThum
bThickness)); |
| 173 } |
| 174 |
| 175 // int testThumbThickness = static_cast<int>(displayedThumbThickn
ess); |
| 176 // thumbRect.setWidth(1); |
| 177 |
| 178 blink::Platform::current()->themeEngine()->paintStateTransition(canvas,
part, startState, endState, progress, blink::WebRect(thumbRect)); |
| 179 return; |
| 180 } |
| 181 |
| 182 blink::WebThemeEngine::State state = blink::WebThemeEngine::StateNormal; |
| 183 if (scrollbar->pressedPart() == ThumbPart) { |
| 184 state = blink::WebThemeEngine::StatePressed; |
| 185 } else if (scrollbar->hoveredPart() == ThumbPart) { |
| 186 state = blink::WebThemeEngine::StateHover; |
| 187 } else { |
| 188 if (scrollbar->orientation() == HorizontalScrollbar) { |
| 189 thumbRect.setY(thumbRect.y() + (m_thumbThickness - kDefaultOverlaySc
rollbarMinThumbThickness)); |
| 190 thumbRect.setHeight(kDefaultOverlayScrollbarMinThumbThickness); |
| 191 } else { |
| 192 thumbRect.setWidth(kDefaultOverlayScrollbarMinThumbThickness); |
| 193 if (!scrollbar->isLeftSideVerticalScrollbar()) |
| 194 thumbRect.setX(thumbRect.x() + (m_thumbThickness - kDefaultOverl
ayScrollbarMinThumbThickness)); |
| 195 } |
| 196 } |
| 197 |
| 198 blink::Platform::current()->themeEngine()->paint(canvas, part, state, blink:
:WebRect(thumbRect), 0); |
156 } | 199 } |
157 | 200 |
158 ScrollbarPart ScrollbarThemeOverlay::hitTest(ScrollbarThemeClient* scrollbar, co
nst IntPoint& position) | 201 ScrollbarPart ScrollbarThemeOverlay::hitTest(ScrollbarThemeClient* scrollbar, co
nst IntPoint& position) |
159 { | 202 { |
160 if (m_allowHitTest == DisallowHitTest) | 203 if (m_allowHitTest == DisallowHitTest) |
161 return NoPart; | 204 return NoPart; |
162 | 205 |
163 return ScrollbarTheme::hitTest(scrollbar, position); | 206 return ScrollbarTheme::hitTest(scrollbar, position); |
164 } | 207 } |
165 | 208 |
166 } // namespace WebCore | 209 } // namespace WebCore |
OLD | NEW |