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