OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/tabs/media_indicator_button.h" | 5 #include "chrome/browser/ui/views/tabs/media_indicator_button.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "chrome/browser/ui/views/tabs/tab.h" | 8 #include "chrome/browser/ui/views/tabs/tab.h" |
9 #include "chrome/browser/ui/views/tabs/tab_controller.h" | 9 #include "chrome/browser/ui/views/tabs/tab_controller.h" |
10 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" | 10 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 views::View* MediaIndicatorButton::GetTooltipHandlerForPoint( | 142 views::View* MediaIndicatorButton::GetTooltipHandlerForPoint( |
143 const gfx::Point& point) { | 143 const gfx::Point& point) { |
144 return NULL; // Tab (the parent View) provides the tooltip. | 144 return NULL; // Tab (the parent View) provides the tooltip. |
145 } | 145 } |
146 | 146 |
147 bool MediaIndicatorButton::OnMousePressed(const ui::MouseEvent& event) { | 147 bool MediaIndicatorButton::OnMousePressed(const ui::MouseEvent& event) { |
148 // Do not handle this mouse event when anything but the left mouse button is | 148 // Do not handle this mouse event when anything but the left mouse button is |
149 // pressed or when any modifier keys are being held down. Instead, the Tab | 149 // pressed or when any modifier keys are being held down. Instead, the Tab |
150 // should react (e.g., middle-click for close, right-click for context menu). | 150 // should react (e.g., middle-click for close, right-click for context menu). |
151 if (event.flags() != ui::EF_LEFT_MOUSE_BUTTON) { | 151 if (event.flags() != ui::EF_LEFT_MOUSE_BUTTON) { |
152 if (state_ != views::CustomButton::STATE_DISABLED) | 152 if (state() != views::CustomButton::STATE_DISABLED) |
153 SetState(views::CustomButton::STATE_NORMAL); // Turn off hover. | 153 SetState(views::CustomButton::STATE_NORMAL); // Turn off hover. |
154 return false; // Event to be handled by Tab. | 154 return false; // Event to be handled by Tab. |
155 } | 155 } |
156 return ImageButton::OnMousePressed(event); | 156 return ImageButton::OnMousePressed(event); |
157 } | 157 } |
158 | 158 |
159 bool MediaIndicatorButton::OnMouseDragged(const ui::MouseEvent& event) { | 159 bool MediaIndicatorButton::OnMouseDragged(const ui::MouseEvent& event) { |
160 const ButtonState previous_state = state(); | 160 const ButtonState previous_state = state(); |
161 const bool ret = ImageButton::OnMouseDragged(event); | 161 const bool ret = ImageButton::OnMouseDragged(event); |
162 if (previous_state != views::CustomButton::STATE_NORMAL && | 162 if (previous_state != views::CustomButton::STATE_NORMAL && |
163 state() == views::CustomButton::STATE_NORMAL) | 163 state() == views::CustomButton::STATE_NORMAL) |
164 content::RecordAction(UserMetricsAction("MediaIndicatorButton_Dragged")); | 164 content::RecordAction(UserMetricsAction("MediaIndicatorButton_Dragged")); |
165 return ret; | 165 return ret; |
166 } | 166 } |
167 | 167 |
168 void MediaIndicatorButton::OnMouseEntered(const ui::MouseEvent& event) { | 168 void MediaIndicatorButton::OnMouseEntered(const ui::MouseEvent& event) { |
169 // If any modifier keys are being held down, do not turn on hover. | 169 // If any modifier keys are being held down, do not turn on hover. |
170 if (state_ != views::CustomButton::STATE_DISABLED && | 170 if (state() != views::CustomButton::STATE_DISABLED && |
171 event.flags() != ui::EF_NONE) { | 171 event.flags() != ui::EF_NONE) { |
172 SetState(views::CustomButton::STATE_NORMAL); | 172 SetState(views::CustomButton::STATE_NORMAL); |
173 return; | 173 return; |
174 } | 174 } |
175 ImageButton::OnMouseEntered(event); | 175 ImageButton::OnMouseEntered(event); |
176 } | 176 } |
177 | 177 |
178 void MediaIndicatorButton::OnMouseMoved(const ui::MouseEvent& event) { | 178 void MediaIndicatorButton::OnMouseMoved(const ui::MouseEvent& event) { |
179 // If any modifier keys are being held down, turn off hover. | 179 // If any modifier keys are being held down, turn off hover. |
180 if (state_ != views::CustomButton::STATE_DISABLED && | 180 if (state() != views::CustomButton::STATE_DISABLED && |
181 event.flags() != ui::EF_NONE) { | 181 event.flags() != ui::EF_NONE) { |
182 SetState(views::CustomButton::STATE_NORMAL); | 182 SetState(views::CustomButton::STATE_NORMAL); |
183 return; | 183 return; |
184 } | 184 } |
185 ImageButton::OnMouseMoved(event); | 185 ImageButton::OnMouseMoved(event); |
186 } | 186 } |
187 | 187 |
188 void MediaIndicatorButton::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 188 void MediaIndicatorButton::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
189 UpdateEnabledForMuteToggle(); | 189 UpdateEnabledForMuteToggle(); |
190 } | 190 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 SkColor color = parent_tab_->button_color(); | 247 SkColor color = parent_tab_->button_color(); |
248 gfx::ImageSkia indicator_image = | 248 gfx::ImageSkia indicator_image = |
249 chrome::GetTabMediaIndicatorImage(state, color).AsImageSkia(); | 249 chrome::GetTabMediaIndicatorImage(state, color).AsImageSkia(); |
250 SetImage(views::CustomButton::STATE_NORMAL, &indicator_image); | 250 SetImage(views::CustomButton::STATE_NORMAL, &indicator_image); |
251 SetImage(views::CustomButton::STATE_DISABLED, &indicator_image); | 251 SetImage(views::CustomButton::STATE_DISABLED, &indicator_image); |
252 gfx::ImageSkia affordance_image = | 252 gfx::ImageSkia affordance_image = |
253 chrome::GetTabMediaIndicatorAffordanceImage(state, color).AsImageSkia(); | 253 chrome::GetTabMediaIndicatorAffordanceImage(state, color).AsImageSkia(); |
254 SetImage(views::CustomButton::STATE_HOVERED, &affordance_image); | 254 SetImage(views::CustomButton::STATE_HOVERED, &affordance_image); |
255 SetImage(views::CustomButton::STATE_PRESSED, &affordance_image); | 255 SetImage(views::CustomButton::STATE_PRESSED, &affordance_image); |
256 } | 256 } |
OLD | NEW |