Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/toolbar/toolbar_button.h" | 5 #include "chrome/browser/ui/views/toolbar/toolbar_button.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
| 28 | 28 |
| 29 ToolbarButton::ToolbarButton(views::ButtonListener* listener, | 29 ToolbarButton::ToolbarButton(views::ButtonListener* listener, |
| 30 ui::MenuModel* model) | 30 ui::MenuModel* model) |
| 31 : views::LabelButton(listener, base::string16()), | 31 : views::LabelButton(listener, base::string16()), |
| 32 model_(model), | 32 model_(model), |
| 33 menu_showing_(false), | 33 menu_showing_(false), |
| 34 y_position_on_lbuttondown_(0), | 34 y_position_on_lbuttondown_(0), |
| 35 ink_drop_animation_controller_( | 35 ink_drop_animation_controller_( |
| 36 views::InkDropAnimationControllerFactory:: | 36 views::InkDropAnimationControllerFactory:: |
| 37 CreateInkDropAnimationController(this)), | 37 CreateInkDropAnimationController(this, this)), |
| 38 show_menu_factory_(this) { | 38 show_menu_factory_(this) { |
| 39 set_context_menu_controller(this); | 39 set_context_menu_controller(this); |
| 40 | 40 |
| 41 const int kInkDropLargeSize = 32; | 41 const int kInkDropLargeSize = 32; |
| 42 const int kInkDropLargeCornerRadius = 5; | 42 const int kInkDropLargeCornerRadius = 5; |
| 43 const int kInkDropSmallSize = 24; | 43 const int kInkDropSmallSize = 24; |
| 44 const int kInkDropSmallCornerRadius = 2; | 44 const int kInkDropSmallCornerRadius = 2; |
| 45 | 45 |
| 46 ink_drop_animation_controller_->SetInkDropSize( | 46 ink_drop_animation_controller_->SetInkDropSize( |
| 47 gfx::Size(kInkDropLargeSize, kInkDropLargeSize), | 47 gfx::Size(kInkDropLargeSize, kInkDropLargeSize), |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 if (IsTriggerableEvent(event)) | 144 if (IsTriggerableEvent(event)) |
| 145 show_menu_factory_.InvalidateWeakPtrs(); | 145 show_menu_factory_.InvalidateWeakPtrs(); |
| 146 | 146 |
| 147 if (!HitTestPoint(event.location())) | 147 if (!HitTestPoint(event.location())) |
| 148 ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN); | 148 ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void ToolbarButton::OnMouseCaptureLost() { | 151 void ToolbarButton::OnMouseCaptureLost() { |
| 152 } | 152 } |
| 153 | 153 |
| 154 void ToolbarButton::OnMouseEntered(const ui::MouseEvent& event) { | |
| 155 UpdateInkDropHoverState(); | |
| 156 } | |
| 157 | |
| 154 void ToolbarButton::OnMouseExited(const ui::MouseEvent& event) { | 158 void ToolbarButton::OnMouseExited(const ui::MouseEvent& event) { |
| 159 UpdateInkDropHoverState(); | |
|
Peter Kasting
2015/11/11 21:41:38
Nit: It might be better to do this below the SetSt
| |
| 160 | |
| 155 // Starting a drag results in a MouseExited, we need to ignore it. | 161 // Starting a drag results in a MouseExited, we need to ignore it. |
| 156 // A right click release triggers an exit event. We want to | 162 // A right click release triggers an exit event. We want to |
| 157 // remain in a PUSHED state until the drop down menu closes. | 163 // remain in a PUSHED state until the drop down menu closes. |
| 158 if (state_ != STATE_DISABLED && !InDrag() && state_ != STATE_PRESSED) | 164 if (state_ != STATE_DISABLED && !InDrag() && state_ != STATE_PRESSED) |
| 159 SetState(STATE_NORMAL); | 165 SetState(STATE_NORMAL); |
| 160 } | 166 } |
| 161 | 167 |
| 162 void ToolbarButton::OnGestureEvent(ui::GestureEvent* event) { | 168 void ToolbarButton::OnGestureEvent(ui::GestureEvent* event) { |
| 163 if (menu_showing_) { | 169 if (menu_showing_) { |
| 164 // While dropdown menu is showing the button should not handle gestures. | 170 // While dropdown menu is showing the button should not handle gestures. |
| 165 event->StopPropagation(); | 171 event->StopPropagation(); |
| 166 return; | 172 return; |
| 167 } | 173 } |
| 168 | 174 |
| 169 LabelButton::OnGestureEvent(event); | 175 LabelButton::OnGestureEvent(event); |
| 170 | 176 |
| 171 views::InkDropState ink_drop_state = views::InkDropState::HIDDEN; | 177 views::InkDropState ink_drop_state = views::InkDropState::HIDDEN; |
| 172 switch (event->type()) { | 178 switch (event->type()) { |
| 173 case ui::ET_GESTURE_TAP_DOWN: | 179 case ui::ET_GESTURE_TAP_DOWN: |
| 174 ink_drop_state = views::InkDropState::ACTION_PENDING; | 180 ink_drop_state = views::InkDropState::ACTION_PENDING; |
| 175 // The ui::ET_GESTURE_TAP_DOWN event needs to be marked as handled so that | 181 // The ui::ET_GESTURE_TAP_DOWN event needs to be marked as handled so that |
| 176 // subsequent events for the gesture are sent to |this|. | 182 // subsequent events for the gesture are sent to |this|. |
| 177 event->SetHandled(); | 183 event->SetHandled(); |
| 178 break; | 184 break; |
| 179 case ui::ET_GESTURE_LONG_PRESS: | 185 case ui::ET_GESTURE_LONG_PRESS: |
| 180 ink_drop_state = views::InkDropState::SLOW_ACTION_PENDING; | 186 ink_drop_state = views::InkDropState::SLOW_ACTION_PENDING; |
| 181 break; | 187 break; |
| 182 case ui::ET_GESTURE_TAP: | |
| 183 ink_drop_state = views::InkDropState::QUICK_ACTION; | |
| 184 break; | |
| 185 case ui::ET_GESTURE_LONG_TAP: | 188 case ui::ET_GESTURE_LONG_TAP: |
| 186 ink_drop_state = views::InkDropState::SLOW_ACTION; | 189 ink_drop_state = views::InkDropState::SLOW_ACTION; |
| 187 break; | 190 break; |
| 191 case ui::ET_GESTURE_SCROLL_BEGIN: | |
| 188 case ui::ET_GESTURE_END: | 192 case ui::ET_GESTURE_END: |
| 189 case ui::ET_GESTURE_TAP_CANCEL: | |
| 190 ink_drop_state = views::InkDropState::HIDDEN; | 193 ink_drop_state = views::InkDropState::HIDDEN; |
| 191 break; | 194 break; |
| 192 default: | 195 default: |
| 193 return; | 196 return; |
| 194 } | 197 } |
| 198 | |
| 199 if (ink_drop_state == views::InkDropState::HIDDEN && | |
| 200 ink_drop_animation_controller_->WillAutoAnimateToHidden()) { | |
| 201 // Some InkDropStates automatically transition to the HIDDEN state so we | |
| 202 // don't make an explicit call. Explicitly animating to HIDDEN in this case | |
| 203 // would prematurely pre-empt these animations. | |
|
Peter Kasting
2015/11/11 21:41:38
Nit: I'd move this comment above the conditional,
| |
| 204 return; | |
| 205 } | |
| 195 ink_drop_animation_controller_->AnimateToState(ink_drop_state); | 206 ink_drop_animation_controller_->AnimateToState(ink_drop_state); |
| 196 } | 207 } |
| 197 | 208 |
| 198 void ToolbarButton::GetAccessibleState(ui::AXViewState* state) { | 209 void ToolbarButton::GetAccessibleState(ui::AXViewState* state) { |
| 199 CustomButton::GetAccessibleState(state); | 210 CustomButton::GetAccessibleState(state); |
| 200 state->role = ui::AX_ROLE_BUTTON_DROP_DOWN; | 211 state->role = ui::AX_ROLE_BUTTON_DROP_DOWN; |
| 201 state->default_action = l10n_util::GetStringUTF16(IDS_APP_ACCACTION_PRESS); | 212 state->default_action = l10n_util::GetStringUTF16(IDS_APP_ACCACTION_PRESS); |
| 202 state->AddStateFlag(ui::AX_STATE_HASPOPUP); | 213 state->AddStateFlag(ui::AX_STATE_HASPOPUP); |
| 203 } | 214 } |
| 204 | 215 |
| 205 scoped_ptr<views::LabelButtonBorder> | 216 scoped_ptr<views::LabelButtonBorder> |
| 206 ToolbarButton::CreateDefaultBorder() const { | 217 ToolbarButton::CreateDefaultBorder() const { |
| 207 scoped_ptr<views::LabelButtonBorder> border = | 218 scoped_ptr<views::LabelButtonBorder> border = |
| 208 views::LabelButton::CreateDefaultBorder(); | 219 views::LabelButton::CreateDefaultBorder(); |
| 209 | 220 |
| 210 ui::ThemeProvider* provider = GetThemeProvider(); | 221 ui::ThemeProvider* provider = GetThemeProvider(); |
| 211 if (provider && provider->UsingSystemTheme()) | 222 if (provider && provider->UsingSystemTheme()) |
| 212 border->set_insets(GetLayoutInsets(TOOLBAR_BUTTON)); | 223 border->set_insets(GetLayoutInsets(TOOLBAR_BUTTON)); |
| 213 | 224 |
| 214 return border.Pass(); | 225 return border.Pass(); |
| 215 } | 226 } |
| 216 | 227 |
| 228 void ToolbarButton::OnEnabledChanged() { | |
| 229 UpdateInkDropHoverState(); | |
| 230 } | |
| 231 | |
| 217 void ToolbarButton::ShowContextMenuForView(View* source, | 232 void ToolbarButton::ShowContextMenuForView(View* source, |
| 218 const gfx::Point& point, | 233 const gfx::Point& point, |
| 219 ui::MenuSourceType source_type) { | 234 ui::MenuSourceType source_type) { |
| 220 if (!enabled()) | 235 if (!enabled()) |
| 221 return; | 236 return; |
| 222 | 237 |
| 223 show_menu_factory_.InvalidateWeakPtrs(); | 238 show_menu_factory_.InvalidateWeakPtrs(); |
| 224 ShowDropDownMenu(source_type); | 239 ShowDropDownMenu(source_type); |
| 225 } | 240 } |
| 226 | 241 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 | 354 |
| 340 // Set the state back to normal after the drop down menu is closed. | 355 // Set the state back to normal after the drop down menu is closed. |
| 341 if (state_ != STATE_DISABLED) | 356 if (state_ != STATE_DISABLED) |
| 342 SetState(STATE_NORMAL); | 357 SetState(STATE_NORMAL); |
| 343 } | 358 } |
| 344 | 359 |
| 345 gfx::Point ToolbarButton::CalculateInkDropCenter() const { | 360 gfx::Point ToolbarButton::CalculateInkDropCenter() const { |
| 346 return GetLocalBounds().CenterPoint(); | 361 return GetLocalBounds().CenterPoint(); |
| 347 } | 362 } |
| 348 | 363 |
| 364 void ToolbarButton::UpdateInkDropHoverState() { | |
| 365 ink_drop_animation_controller_->SetHovered(ShouldShowInkDropHover()); | |
| 366 } | |
| 367 | |
| 349 const char* ToolbarButton::GetClassName() const { | 368 const char* ToolbarButton::GetClassName() const { |
| 350 return "ToolbarButton"; | 369 return "ToolbarButton"; |
| 351 } | 370 } |
| OLD | NEW |