Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2012 Google Inc. All rights reserved. | 3 * Copyright (C) 2012 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 | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 using namespace HTMLNames; | 54 using namespace HTMLNames; |
| 55 | 55 |
| 56 static const AtomicString& getMediaControlCurrentTimeDisplayElementShadowPseudoI d(); | 56 static const AtomicString& getMediaControlCurrentTimeDisplayElementShadowPseudoI d(); |
| 57 static const AtomicString& getMediaControlTimeRemainingDisplayElementShadowPseud oId(); | 57 static const AtomicString& getMediaControlTimeRemainingDisplayElementShadowPseud oId(); |
| 58 | 58 |
| 59 static const double fadeInDuration = 0.1; | 59 static const double fadeInDuration = 0.1; |
| 60 static const double fadeOutDuration = 0.3; | 60 static const double fadeOutDuration = 0.3; |
| 61 | 61 |
| 62 MediaControlPanelElement::MediaControlPanelElement(MediaControls& mediaControls) | 62 MediaControlPanelElement::MediaControlPanelElement(MediaControls& mediaControls) |
| 63 : MediaControlDivElement(mediaControls, MediaControlsPanel) | 63 : MediaControlDivElement(mediaControls, MediaControlsPanel) |
| 64 , m_canBeDragged(false) | |
| 65 , m_isBeingDragged(false) | |
| 66 , m_isDisplayed(false) | 64 , m_isDisplayed(false) |
| 67 , m_opaque(true) | 65 , m_opaque(true) |
| 68 , m_transitionTimer(this, &MediaControlPanelElement::transitionTimerFired) | 66 , m_transitionTimer(this, &MediaControlPanelElement::transitionTimerFired) |
| 69 { | 67 { |
| 70 } | 68 } |
| 71 | 69 |
| 72 PassRefPtr<MediaControlPanelElement> MediaControlPanelElement::create(MediaContr ols& mediaControls) | 70 PassRefPtr<MediaControlPanelElement> MediaControlPanelElement::create(MediaContr ols& mediaControls) |
| 73 { | 71 { |
| 74 return adoptRef(new MediaControlPanelElement(mediaControls)); | 72 return adoptRef(new MediaControlPanelElement(mediaControls)); |
| 75 } | 73 } |
| 76 | 74 |
| 77 const AtomicString& MediaControlPanelElement::shadowPseudoId() const | 75 const AtomicString& MediaControlPanelElement::shadowPseudoId() const |
| 78 { | 76 { |
| 79 DEFINE_STATIC_LOCAL(AtomicString, id, ("-webkit-media-controls-panel", Atomi cString::ConstructFromLiteral)); | 77 DEFINE_STATIC_LOCAL(AtomicString, id, ("-webkit-media-controls-panel", Atomi cString::ConstructFromLiteral)); |
| 80 return id; | 78 return id; |
| 81 } | 79 } |
| 82 | 80 |
| 83 void MediaControlPanelElement::startDrag(const LayoutPoint& eventLocation) | |
| 84 { | |
| 85 if (!m_canBeDragged) | |
| 86 return; | |
| 87 | |
| 88 if (m_isBeingDragged) | |
| 89 return; | |
| 90 | |
| 91 RenderObject* renderer = this->renderer(); | |
| 92 if (!renderer || !renderer->isBox()) | |
| 93 return; | |
| 94 | |
| 95 LocalFrame* frame = document().frame(); | |
| 96 if (!frame) | |
| 97 return; | |
| 98 | |
| 99 m_lastDragEventLocation = eventLocation; | |
| 100 | |
| 101 frame->eventHandler().setCapturingMouseEventsNode(this); | |
| 102 | |
| 103 m_isBeingDragged = true; | |
| 104 } | |
| 105 | |
| 106 void MediaControlPanelElement::continueDrag(const LayoutPoint& eventLocation) | |
| 107 { | |
| 108 if (!m_isBeingDragged) | |
| 109 return; | |
| 110 | |
| 111 LayoutSize distanceDragged = eventLocation - m_lastDragEventLocation; | |
| 112 m_cumulativeDragOffset.move(distanceDragged); | |
| 113 m_lastDragEventLocation = eventLocation; | |
| 114 setPosition(m_cumulativeDragOffset); | |
| 115 } | |
| 116 | |
| 117 void MediaControlPanelElement::endDrag() | |
| 118 { | |
| 119 if (!m_isBeingDragged) | |
| 120 return; | |
| 121 | |
| 122 m_isBeingDragged = false; | |
| 123 | |
| 124 LocalFrame* frame = document().frame(); | |
| 125 if (!frame) | |
| 126 return; | |
| 127 | |
| 128 frame->eventHandler().setCapturingMouseEventsNode(nullptr); | |
| 129 } | |
| 130 | |
| 131 void MediaControlPanelElement::startTimer() | 81 void MediaControlPanelElement::startTimer() |
| 132 { | 82 { |
| 133 stopTimer(); | 83 stopTimer(); |
| 134 | 84 |
| 135 // The timer is required to set the property display:'none' on the panel, | 85 // The timer is required to set the property display:'none' on the panel, |
| 136 // such that captions are correctly displayed at the bottom of the video | 86 // such that captions are correctly displayed at the bottom of the video |
| 137 // at the end of the fadeout transition. | 87 // at the end of the fadeout transition. |
| 138 // FIXME: Racing a transition with a setTimeout like this is wrong. | 88 // FIXME: Racing a transition with a setTimeout like this is wrong. |
| 139 m_transitionTimer.startOneShot(fadeOutDuration, FROM_HERE); | 89 m_transitionTimer.startOneShot(fadeOutDuration, FROM_HERE); |
| 140 } | 90 } |
| 141 | 91 |
| 142 void MediaControlPanelElement::stopTimer() | 92 void MediaControlPanelElement::stopTimer() |
| 143 { | 93 { |
| 144 if (m_transitionTimer.isActive()) | 94 if (m_transitionTimer.isActive()) |
| 145 m_transitionTimer.stop(); | 95 m_transitionTimer.stop(); |
| 146 } | 96 } |
| 147 | 97 |
| 148 void MediaControlPanelElement::transitionTimerFired(Timer<MediaControlPanelEleme nt>*) | 98 void MediaControlPanelElement::transitionTimerFired(Timer<MediaControlPanelEleme nt>*) |
| 149 { | 99 { |
| 150 if (!m_opaque) | 100 if (!m_opaque) |
| 151 hide(); | 101 hide(); |
| 152 | 102 |
| 153 stopTimer(); | 103 stopTimer(); |
| 154 } | 104 } |
| 155 | 105 |
| 156 void MediaControlPanelElement::setPosition(const LayoutPoint& position) | |
| 157 { | |
| 158 // FIXME: Do we really want to up-convert these to doubles and not round? cr bug.com/350474 | |
| 159 double left = position.x().toFloat(); | |
| 160 double top = position.y().toFloat(); | |
| 161 | |
| 162 // Set the left and top to control the panel's position; this depends on it being absolute positioned. | |
| 163 // Set the margin to zero since the position passed in will already include the effect of the margin. | |
| 164 setInlineStyleProperty(CSSPropertyLeft, left, CSSPrimitiveValue::CSS_PX); | |
| 165 setInlineStyleProperty(CSSPropertyTop, top, CSSPrimitiveValue::CSS_PX); | |
| 166 setInlineStyleProperty(CSSPropertyMarginLeft, 0.0, CSSPrimitiveValue::CSS_PX ); | |
| 167 setInlineStyleProperty(CSSPropertyMarginTop, 0.0, CSSPrimitiveValue::CSS_PX) ; | |
| 168 | |
| 169 classList().add("dragged", IGNORE_EXCEPTION); | |
| 170 } | |
| 171 | |
| 172 void MediaControlPanelElement::resetPosition() | |
| 173 { | |
| 174 removeInlineStyleProperty(CSSPropertyLeft); | |
| 175 removeInlineStyleProperty(CSSPropertyTop); | |
| 176 removeInlineStyleProperty(CSSPropertyMarginLeft); | |
| 177 removeInlineStyleProperty(CSSPropertyMarginTop); | |
| 178 | |
| 179 classList().remove("dragged", IGNORE_EXCEPTION); | |
| 180 | |
| 181 m_cumulativeDragOffset.setX(0); | |
| 182 m_cumulativeDragOffset.setY(0); | |
| 183 } | |
| 184 | |
| 185 void MediaControlPanelElement::makeOpaque() | 106 void MediaControlPanelElement::makeOpaque() |
| 186 { | 107 { |
| 187 if (m_opaque) | 108 if (m_opaque) |
| 188 return; | 109 return; |
| 189 | 110 |
| 190 setInlineStyleProperty(CSSPropertyTransitionProperty, CSSPropertyOpacity); | 111 setInlineStyleProperty(CSSPropertyTransitionProperty, CSSPropertyOpacity); |
| 191 setInlineStyleProperty(CSSPropertyTransitionDuration, fadeInDuration, CSSPri mitiveValue::CSS_S); | 112 setInlineStyleProperty(CSSPropertyTransitionDuration, fadeInDuration, CSSPri mitiveValue::CSS_S); |
| 192 setInlineStyleProperty(CSSPropertyOpacity, 1.0, CSSPrimitiveValue::CSS_NUMBE R); | 113 setInlineStyleProperty(CSSPropertyOpacity, 1.0, CSSPrimitiveValue::CSS_NUMBE R); |
| 193 | 114 |
| 194 m_opaque = true; | 115 m_opaque = true; |
| 195 | 116 |
| 196 if (m_isDisplayed) | 117 if (m_isDisplayed) |
| 197 show(); | 118 show(); |
| 198 } | 119 } |
| 199 | 120 |
| 200 void MediaControlPanelElement::makeTransparent() | 121 void MediaControlPanelElement::makeTransparent() |
| 201 { | 122 { |
| 202 if (!m_opaque) | 123 if (!m_opaque) |
| 203 return; | 124 return; |
| 204 | 125 |
| 205 setInlineStyleProperty(CSSPropertyTransitionProperty, CSSPropertyOpacity); | 126 setInlineStyleProperty(CSSPropertyTransitionProperty, CSSPropertyOpacity); |
| 206 setInlineStyleProperty(CSSPropertyTransitionDuration, fadeOutDuration, CSSPr imitiveValue::CSS_S); | 127 setInlineStyleProperty(CSSPropertyTransitionDuration, fadeOutDuration, CSSPr imitiveValue::CSS_S); |
| 207 setInlineStyleProperty(CSSPropertyOpacity, 0.0, CSSPrimitiveValue::CSS_NUMBE R); | 128 setInlineStyleProperty(CSSPropertyOpacity, 0.0, CSSPrimitiveValue::CSS_NUMBE R); |
| 208 | 129 |
| 209 m_opaque = false; | 130 m_opaque = false; |
| 210 startTimer(); | 131 startTimer(); |
| 211 } | 132 } |
| 212 | 133 |
| 213 void MediaControlPanelElement::defaultEventHandler(Event* event) | |
|
adamk
2014/03/14 23:42:56
It's strange that we'd actually run this code...th
philipj_slow
2014/03/15 03:02:36
The defaultEventHandler implementations in this fi
| |
| 214 { | |
| 215 MediaControlDivElement::defaultEventHandler(event); | |
| 216 | |
| 217 if (event->isMouseEvent()) { | |
| 218 LayoutPoint location = toMouseEvent(event)->absoluteLocation(); | |
| 219 if (event->type() == EventTypeNames::mousedown && event->target() == thi s) { | |
| 220 startDrag(location); | |
| 221 event->setDefaultHandled(); | |
| 222 } else if (event->type() == EventTypeNames::mousemove && m_isBeingDragge d) | |
| 223 continueDrag(location); | |
| 224 else if (event->type() == EventTypeNames::mouseup && m_isBeingDragged) { | |
| 225 continueDrag(location); | |
| 226 endDrag(); | |
| 227 event->setDefaultHandled(); | |
| 228 } | |
| 229 } | |
| 230 } | |
| 231 | |
| 232 void MediaControlPanelElement::setCanBeDragged(bool canBeDragged) | |
| 233 { | |
| 234 if (m_canBeDragged == canBeDragged) | |
| 235 return; | |
| 236 | |
| 237 m_canBeDragged = canBeDragged; | |
| 238 | |
| 239 if (!canBeDragged) | |
| 240 endDrag(); | |
| 241 } | |
| 242 | |
| 243 void MediaControlPanelElement::setIsDisplayed(bool isDisplayed) | 134 void MediaControlPanelElement::setIsDisplayed(bool isDisplayed) |
| 244 { | 135 { |
| 245 m_isDisplayed = isDisplayed; | 136 m_isDisplayed = isDisplayed; |
| 246 } | 137 } |
| 247 | 138 |
| 248 // ---------------------------- | 139 // ---------------------------- |
| 249 | 140 |
| 250 MediaControlPanelEnclosureElement::MediaControlPanelEnclosureElement(MediaContro ls& mediaControls) | 141 MediaControlPanelEnclosureElement::MediaControlPanelEnclosureElement(MediaContro ls& mediaControls) |
| 251 // Mapping onto same MediaControlElementType as panel element, since it has similar properties. | 142 // Mapping onto same MediaControlElementType as panel element, since it has similar properties. |
| 252 : MediaControlDivElement(mediaControls, MediaControlsPanel) | 143 : MediaControlDivElement(mediaControls, MediaControlsPanel) |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 782 float fontSize = smallestDimension * 0.05f; | 673 float fontSize = smallestDimension * 0.05f; |
| 783 if (fontSize != m_fontSize) { | 674 if (fontSize != m_fontSize) { |
| 784 m_fontSize = fontSize; | 675 m_fontSize = fontSize; |
| 785 setInlineStyleProperty(CSSPropertyFontSize, fontSize, CSSPrimitiveValue: :CSS_PX); | 676 setInlineStyleProperty(CSSPropertyFontSize, fontSize, CSSPrimitiveValue: :CSS_PX); |
| 786 } | 677 } |
| 787 } | 678 } |
| 788 | 679 |
| 789 // ---------------------------- | 680 // ---------------------------- |
| 790 | 681 |
| 791 } // namespace WebCore | 682 } // namespace WebCore |
| OLD | NEW |