OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
3 * Copyright (C) 2010 Google Inc. All rights reserved. | 3 * Copyright (C) 2010 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 #include "core/layout/LayoutSliderThumb.h" | 46 #include "core/layout/LayoutSliderThumb.h" |
47 #include "core/layout/LayoutTheme.h" | 47 #include "core/layout/LayoutTheme.h" |
48 #include "core/page/EventHandler.h" | 48 #include "core/page/EventHandler.h" |
49 | 49 |
50 namespace blink { | 50 namespace blink { |
51 | 51 |
52 using namespace HTMLNames; | 52 using namespace HTMLNames; |
53 | 53 |
54 inline static bool hasVerticalAppearance(HTMLInputElement* input) | 54 inline static bool hasVerticalAppearance(HTMLInputElement* input) |
55 { | 55 { |
56 ASSERT(input->renderer()); | 56 ASSERT(input->layoutObject()); |
57 LayoutStyle* sliderStyle = input->renderer()->style(); | 57 LayoutStyle* sliderStyle = input->layoutObject()->style(); |
58 | 58 |
59 return sliderStyle->appearance() == SliderVerticalPart; | 59 return sliderStyle->appearance() == SliderVerticalPart; |
60 } | 60 } |
61 | 61 |
62 inline SliderThumbElement::SliderThumbElement(Document& document) | 62 inline SliderThumbElement::SliderThumbElement(Document& document) |
63 : HTMLDivElement(document) | 63 : HTMLDivElement(document) |
64 , m_inDragMode(false) | 64 , m_inDragMode(false) |
65 { | 65 { |
66 } | 66 } |
67 | 67 |
68 PassRefPtrWillBeRawPtr<SliderThumbElement> SliderThumbElement::create(Document&
document) | 68 PassRefPtrWillBeRawPtr<SliderThumbElement> SliderThumbElement::create(Document&
document) |
69 { | 69 { |
70 RefPtrWillBeRawPtr<SliderThumbElement> element = adoptRefWillBeNoop(new Slid
erThumbElement(document)); | 70 RefPtrWillBeRawPtr<SliderThumbElement> element = adoptRefWillBeNoop(new Slid
erThumbElement(document)); |
71 element->setAttribute(idAttr, ShadowElementNames::sliderThumb()); | 71 element->setAttribute(idAttr, ShadowElementNames::sliderThumb()); |
72 return element.release(); | 72 return element.release(); |
73 } | 73 } |
74 | 74 |
75 void SliderThumbElement::setPositionFromValue() | 75 void SliderThumbElement::setPositionFromValue() |
76 { | 76 { |
77 // Since the code to calculate position is in the LayoutSliderThumb layout | 77 // Since the code to calculate position is in the LayoutSliderThumb layout |
78 // path, we don't actually update the value here. Instead, we poke at the | 78 // path, we don't actually update the value here. Instead, we poke at the |
79 // renderer directly to trigger layout. | 79 // renderer directly to trigger layout. |
80 if (renderer()) | 80 if (layoutObject()) |
81 renderer()->setNeedsLayoutAndFullPaintInvalidation(); | 81 layoutObject()->setNeedsLayoutAndFullPaintInvalidation(); |
82 } | 82 } |
83 | 83 |
84 LayoutObject* SliderThumbElement::createRenderer(const LayoutStyle&) | 84 LayoutObject* SliderThumbElement::createRenderer(const LayoutStyle&) |
85 { | 85 { |
86 return new LayoutSliderThumb(this); | 86 return new LayoutSliderThumb(this); |
87 } | 87 } |
88 | 88 |
89 bool SliderThumbElement::isDisabledFormControl() const | 89 bool SliderThumbElement::isDisabledFormControl() const |
90 { | 90 { |
91 return hostInput() && hostInput()->isDisabledFormControl(); | 91 return hostInput() && hostInput()->isDisabledFormControl(); |
(...skipping 19 matching lines...) Expand all Loading... |
111 RefPtrWillBeRawPtr<SliderThumbElement> protector(this); | 111 RefPtrWillBeRawPtr<SliderThumbElement> protector(this); |
112 startDragging(); | 112 startDragging(); |
113 setPositionFromPoint(point); | 113 setPositionFromPoint(point); |
114 } | 114 } |
115 | 115 |
116 void SliderThumbElement::setPositionFromPoint(const LayoutPoint& point) | 116 void SliderThumbElement::setPositionFromPoint(const LayoutPoint& point) |
117 { | 117 { |
118 RefPtrWillBeRawPtr<HTMLInputElement> input(hostInput()); | 118 RefPtrWillBeRawPtr<HTMLInputElement> input(hostInput()); |
119 Element* trackElement = input->closedShadowRoot()->getElementById(ShadowElem
entNames::sliderTrack()); | 119 Element* trackElement = input->closedShadowRoot()->getElementById(ShadowElem
entNames::sliderTrack()); |
120 | 120 |
121 if (!input->renderer() || !layoutBox() || !trackElement->layoutBox()) | 121 if (!input->layoutObject() || !layoutBox() || !trackElement->layoutBox()) |
122 return; | 122 return; |
123 | 123 |
124 LayoutPoint offset = roundedLayoutPoint(input->renderer()->absoluteToLocal(F
loatPoint(point), UseTransforms)); | 124 LayoutPoint offset = roundedLayoutPoint(input->layoutObject()->absoluteToLoc
al(FloatPoint(point), UseTransforms)); |
125 bool isVertical = hasVerticalAppearance(input.get()); | 125 bool isVertical = hasVerticalAppearance(input.get()); |
126 bool isLeftToRightDirection = layoutBox()->style()->isLeftToRightDirection()
; | 126 bool isLeftToRightDirection = layoutBox()->style()->isLeftToRightDirection()
; |
127 LayoutUnit trackSize; | 127 LayoutUnit trackSize; |
128 LayoutUnit position; | 128 LayoutUnit position; |
129 LayoutUnit currentPosition; | 129 LayoutUnit currentPosition; |
130 // We need to calculate currentPosition from absolute points becaue the | 130 // We need to calculate currentPosition from absolute points becaue the |
131 // renderer for this node is usually on a layer and layoutBox()->x() and | 131 // renderer for this node is usually on a layer and layoutBox()->x() and |
132 // y() are unusable. | 132 // y() are unusable. |
133 // FIXME: This should probably respect transforms. | 133 // FIXME: This should probably respect transforms. |
134 LayoutPoint absoluteThumbOrigin = layoutBox()->absoluteBoundingBoxRectIgnori
ngTransforms().location(); | 134 LayoutPoint absoluteThumbOrigin = layoutBox()->absoluteBoundingBoxRectIgnori
ngTransforms().location(); |
135 LayoutPoint absoluteSliderContentOrigin = roundedLayoutPoint(input->renderer
()->localToAbsolute()); | 135 LayoutPoint absoluteSliderContentOrigin = roundedLayoutPoint(input->layoutOb
ject()->localToAbsolute()); |
136 IntRect trackBoundingBox = trackElement->renderer()->absoluteBoundingBoxRect
IgnoringTransforms(); | 136 IntRect trackBoundingBox = trackElement->layoutObject()->absoluteBoundingBox
RectIgnoringTransforms(); |
137 IntRect inputBoundingBox = input->renderer()->absoluteBoundingBoxRectIgnorin
gTransforms(); | 137 IntRect inputBoundingBox = input->layoutObject()->absoluteBoundingBoxRectIgn
oringTransforms(); |
138 if (isVertical) { | 138 if (isVertical) { |
139 trackSize = trackElement->layoutBox()->contentHeight() - layoutBox()->si
ze().height(); | 139 trackSize = trackElement->layoutBox()->contentHeight() - layoutBox()->si
ze().height(); |
140 position = offset.y() - layoutBox()->size().height() / 2 - trackBounding
Box.y() + inputBoundingBox.y() - layoutBox()->marginBottom(); | 140 position = offset.y() - layoutBox()->size().height() / 2 - trackBounding
Box.y() + inputBoundingBox.y() - layoutBox()->marginBottom(); |
141 currentPosition = absoluteThumbOrigin.y() - absoluteSliderContentOrigin.
y(); | 141 currentPosition = absoluteThumbOrigin.y() - absoluteSliderContentOrigin.
y(); |
142 } else { | 142 } else { |
143 trackSize = trackElement->layoutBox()->contentWidth() - layoutBox()->siz
e().width(); | 143 trackSize = trackElement->layoutBox()->contentWidth() - layoutBox()->siz
e().width(); |
144 position = offset.x() - layoutBox()->size().width() / 2 - trackBoundingB
ox.x() + inputBoundingBox.x(); | 144 position = offset.x() - layoutBox()->size().width() / 2 - trackBoundingB
ox.x() + inputBoundingBox.x(); |
145 position -= isLeftToRightDirection ? layoutBox()->marginLeft() : layoutB
ox()->marginRight(); | 145 position -= isLeftToRightDirection ? layoutBox()->marginLeft() : layoutB
ox()->marginRight(); |
146 currentPosition = absoluteThumbOrigin.x() - absoluteSliderContentOrigin.
x(); | 146 currentPosition = absoluteThumbOrigin.x() - absoluteSliderContentOrigin.
x(); |
147 } | 147 } |
(...skipping 12 matching lines...) Expand all Loading... |
160 if ((closestPosition - position).abs() <= snappingThreshold) | 160 if ((closestPosition - position).abs() <= snappingThreshold) |
161 value = closest; | 161 value = closest; |
162 } | 162 } |
163 | 163 |
164 String valueString = serializeForNumberType(value); | 164 String valueString = serializeForNumberType(value); |
165 if (valueString == input->value()) | 165 if (valueString == input->value()) |
166 return; | 166 return; |
167 | 167 |
168 // FIXME: This is no longer being set from renderer. Consider updating the m
ethod name. | 168 // FIXME: This is no longer being set from renderer. Consider updating the m
ethod name. |
169 input->setValueFromRenderer(valueString); | 169 input->setValueFromRenderer(valueString); |
170 if (renderer()) | 170 if (layoutObject()) |
171 renderer()->setNeedsLayoutAndFullPaintInvalidation(); | 171 layoutObject()->setNeedsLayoutAndFullPaintInvalidation(); |
172 } | 172 } |
173 | 173 |
174 void SliderThumbElement::startDragging() | 174 void SliderThumbElement::startDragging() |
175 { | 175 { |
176 if (LocalFrame* frame = document().frame()) { | 176 if (LocalFrame* frame = document().frame()) { |
177 frame->eventHandler().setCapturingMouseEventsNode(this); | 177 frame->eventHandler().setCapturingMouseEventsNode(this); |
178 m_inDragMode = true; | 178 m_inDragMode = true; |
179 } | 179 } |
180 } | 180 } |
181 | 181 |
182 void SliderThumbElement::stopDragging() | 182 void SliderThumbElement::stopDragging() |
183 { | 183 { |
184 if (!m_inDragMode) | 184 if (!m_inDragMode) |
185 return; | 185 return; |
186 | 186 |
187 if (LocalFrame* frame = document().frame()) | 187 if (LocalFrame* frame = document().frame()) |
188 frame->eventHandler().setCapturingMouseEventsNode(nullptr); | 188 frame->eventHandler().setCapturingMouseEventsNode(nullptr); |
189 m_inDragMode = false; | 189 m_inDragMode = false; |
190 if (renderer()) | 190 if (layoutObject()) |
191 renderer()->setNeedsLayoutAndFullPaintInvalidation(); | 191 layoutObject()->setNeedsLayoutAndFullPaintInvalidation(); |
192 if (hostInput()) | 192 if (hostInput()) |
193 hostInput()->dispatchFormControlChangeEvent(); | 193 hostInput()->dispatchFormControlChangeEvent(); |
194 } | 194 } |
195 | 195 |
196 void SliderThumbElement::defaultEventHandler(Event* event) | 196 void SliderThumbElement::defaultEventHandler(Event* event) |
197 { | 197 { |
198 if (!event->isMouseEvent()) { | 198 if (!event->isMouseEvent()) { |
199 HTMLDivElement::defaultEventHandler(event); | 199 HTMLDivElement::defaultEventHandler(event); |
200 return; | 200 return; |
201 } | 201 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 | 273 |
274 static const AtomicString& mediaSliderThumbShadowPartId() | 274 static const AtomicString& mediaSliderThumbShadowPartId() |
275 { | 275 { |
276 DEFINE_STATIC_LOCAL(const AtomicString, mediaSliderThumb, ("-webkit-media-sl
ider-thumb", AtomicString::ConstructFromLiteral)); | 276 DEFINE_STATIC_LOCAL(const AtomicString, mediaSliderThumb, ("-webkit-media-sl
ider-thumb", AtomicString::ConstructFromLiteral)); |
277 return mediaSliderThumb; | 277 return mediaSliderThumb; |
278 } | 278 } |
279 | 279 |
280 const AtomicString& SliderThumbElement::shadowPseudoId() const | 280 const AtomicString& SliderThumbElement::shadowPseudoId() const |
281 { | 281 { |
282 HTMLInputElement* input = hostInput(); | 282 HTMLInputElement* input = hostInput(); |
283 if (!input || !input->renderer()) | 283 if (!input || !input->layoutObject()) |
284 return sliderThumbShadowPartId(); | 284 return sliderThumbShadowPartId(); |
285 | 285 |
286 LayoutStyle* sliderStyle = input->renderer()->style(); | 286 LayoutStyle* sliderStyle = input->layoutObject()->style(); |
287 switch (sliderStyle->appearance()) { | 287 switch (sliderStyle->appearance()) { |
288 case MediaSliderPart: | 288 case MediaSliderPart: |
289 case MediaSliderThumbPart: | 289 case MediaSliderThumbPart: |
290 case MediaVolumeSliderPart: | 290 case MediaVolumeSliderPart: |
291 case MediaVolumeSliderThumbPart: | 291 case MediaVolumeSliderThumbPart: |
292 case MediaFullScreenVolumeSliderPart: | 292 case MediaFullScreenVolumeSliderPart: |
293 case MediaFullScreenVolumeSliderThumbPart: | 293 case MediaFullScreenVolumeSliderThumbPart: |
294 return mediaSliderThumbShadowPartId(); | 294 return mediaSliderThumbShadowPartId(); |
295 default: | 295 default: |
296 return sliderThumbShadowPartId(); | 296 return sliderThumbShadowPartId(); |
(...skipping 12 matching lines...) Expand all Loading... |
309 LayoutObject* SliderContainerElement::createRenderer(const LayoutStyle&) | 309 LayoutObject* SliderContainerElement::createRenderer(const LayoutStyle&) |
310 { | 310 { |
311 return new LayoutSliderContainer(this); | 311 return new LayoutSliderContainer(this); |
312 } | 312 } |
313 | 313 |
314 const AtomicString& SliderContainerElement::shadowPseudoId() const | 314 const AtomicString& SliderContainerElement::shadowPseudoId() const |
315 { | 315 { |
316 DEFINE_STATIC_LOCAL(const AtomicString, mediaSliderContainer, ("-webkit-medi
a-slider-container", AtomicString::ConstructFromLiteral)); | 316 DEFINE_STATIC_LOCAL(const AtomicString, mediaSliderContainer, ("-webkit-medi
a-slider-container", AtomicString::ConstructFromLiteral)); |
317 DEFINE_STATIC_LOCAL(const AtomicString, sliderContainer, ("-webkit-slider-co
ntainer", AtomicString::ConstructFromLiteral)); | 317 DEFINE_STATIC_LOCAL(const AtomicString, sliderContainer, ("-webkit-slider-co
ntainer", AtomicString::ConstructFromLiteral)); |
318 | 318 |
319 if (!shadowHost() || !shadowHost()->renderer()) | 319 if (!shadowHost() || !shadowHost()->layoutObject()) |
320 return sliderContainer; | 320 return sliderContainer; |
321 | 321 |
322 LayoutStyle* sliderStyle = shadowHost()->renderer()->style(); | 322 LayoutStyle* sliderStyle = shadowHost()->layoutObject()->style(); |
323 switch (sliderStyle->appearance()) { | 323 switch (sliderStyle->appearance()) { |
324 case MediaSliderPart: | 324 case MediaSliderPart: |
325 case MediaSliderThumbPart: | 325 case MediaSliderThumbPart: |
326 case MediaVolumeSliderPart: | 326 case MediaVolumeSliderPart: |
327 case MediaVolumeSliderThumbPart: | 327 case MediaVolumeSliderThumbPart: |
328 case MediaFullScreenVolumeSliderPart: | 328 case MediaFullScreenVolumeSliderPart: |
329 case MediaFullScreenVolumeSliderThumbPart: | 329 case MediaFullScreenVolumeSliderThumbPart: |
330 return mediaSliderContainer; | 330 return mediaSliderContainer; |
331 default: | 331 default: |
332 return sliderContainer; | 332 return sliderContainer; |
333 } | 333 } |
334 } | 334 } |
335 | 335 |
336 } | 336 } |
OLD | NEW |