| 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_action_view.h" | 5 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 // We should only get a button pressed event with a non-enabled action if | 166 // We should only get a button pressed event with a non-enabled action if |
| 167 // the left-click behavior should open the menu. | 167 // the left-click behavior should open the menu. |
| 168 DCHECK(view_controller_->DisabledClickOpensMenu()); | 168 DCHECK(view_controller_->DisabledClickOpensMenu()); |
| 169 context_menu_controller()->ShowContextMenuForView(this, point, | 169 context_menu_controller()->ShowContextMenuForView(this, point, |
| 170 ui::MENU_SOURCE_NONE); | 170 ui::MENU_SOURCE_NONE); |
| 171 } else { | 171 } else { |
| 172 view_controller_->ExecuteAction(true); | 172 view_controller_->ExecuteAction(true); |
| 173 } | 173 } |
| 174 } | 174 } |
| 175 | 175 |
| 176 void ToolbarActionView::AddInkDropLayer(ui::Layer* ink_drop_layer) { | |
| 177 SetPaintToLayer(true); | |
| 178 SetFillsBoundsOpaquely(false); | |
| 179 image()->SetPaintToLayer(true); | |
| 180 image()->SetFillsBoundsOpaquely(false); | |
| 181 | |
| 182 layer()->Add(ink_drop_layer); | |
| 183 layer()->StackAtBottom(ink_drop_layer); | |
| 184 } | |
| 185 | |
| 186 void ToolbarActionView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { | |
| 187 layer()->Remove(ink_drop_layer); | |
| 188 | |
| 189 image()->SetFillsBoundsOpaquely(true); | |
| 190 image()->SetPaintToLayer(false); | |
| 191 SetPaintToLayer(false); | |
| 192 } | |
| 193 | |
| 194 gfx::ImageSkia ToolbarActionView::GetIconForTest() { | 176 gfx::ImageSkia ToolbarActionView::GetIconForTest() { |
| 195 return GetImage(views::Button::STATE_NORMAL); | 177 return GetImage(views::Button::STATE_NORMAL); |
| 196 } | 178 } |
| 197 | 179 |
| 198 void ToolbarActionView::set_context_menu_callback_for_testing( | 180 void ToolbarActionView::set_context_menu_callback_for_testing( |
| 199 base::Callback<void(ToolbarActionView*)>* callback) { | 181 base::Callback<void(ToolbarActionView*)>* callback) { |
| 200 context_menu_callback = callback; | 182 context_menu_callback = callback; |
| 201 } | 183 } |
| 202 | 184 |
| 203 gfx::Size ToolbarActionView::GetPreferredSize() const { | 185 gfx::Size ToolbarActionView::GetPreferredSize() const { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 232 void ToolbarActionView::ViewHierarchyChanged( | 214 void ToolbarActionView::ViewHierarchyChanged( |
| 233 const ViewHierarchyChangedDetails& details) { | 215 const ViewHierarchyChangedDetails& details) { |
| 234 if (details.is_add && !called_register_command_ && GetFocusManager()) { | 216 if (details.is_add && !called_register_command_ && GetFocusManager()) { |
| 235 view_controller_->RegisterCommand(); | 217 view_controller_->RegisterCommand(); |
| 236 called_register_command_ = true; | 218 called_register_command_ = true; |
| 237 } | 219 } |
| 238 | 220 |
| 239 MenuButton::ViewHierarchyChanged(details); | 221 MenuButton::ViewHierarchyChanged(details); |
| 240 } | 222 } |
| 241 | 223 |
| 224 void ToolbarActionView::AddInkDropLayer(ui::Layer* ink_drop_layer) { |
| 225 SetPaintToLayer(true); |
| 226 SetFillsBoundsOpaquely(false); |
| 227 image()->SetPaintToLayer(true); |
| 228 image()->SetFillsBoundsOpaquely(false); |
| 229 |
| 230 layer()->Add(ink_drop_layer); |
| 231 layer()->StackAtBottom(ink_drop_layer); |
| 232 } |
| 233 |
| 234 void ToolbarActionView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { |
| 235 layer()->Remove(ink_drop_layer); |
| 236 |
| 237 image()->SetFillsBoundsOpaquely(true); |
| 238 image()->SetPaintToLayer(false); |
| 239 SetPaintToLayer(false); |
| 240 } |
| 241 |
| 242 views::View* ToolbarActionView::GetAsView() { | 242 views::View* ToolbarActionView::GetAsView() { |
| 243 return this; | 243 return this; |
| 244 } | 244 } |
| 245 | 245 |
| 246 views::FocusManager* ToolbarActionView::GetFocusManagerForAccelerator() { | 246 views::FocusManager* ToolbarActionView::GetFocusManagerForAccelerator() { |
| 247 return GetFocusManager(); | 247 return GetFocusManager(); |
| 248 } | 248 } |
| 249 | 249 |
| 250 views::View* ToolbarActionView::GetReferenceViewForPopup() { | 250 views::View* ToolbarActionView::GetReferenceViewForPopup() { |
| 251 // Browser actions in the overflow menu can still show popups, so we may need | 251 // Browser actions in the overflow menu can still show popups, so we may need |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 weak_factory_.GetWeakPtr(), | 295 weak_factory_.GetWeakPtr(), |
| 296 source_type); | 296 source_type); |
| 297 } | 297 } |
| 298 if (CloseActiveMenuIfNeeded()) | 298 if (CloseActiveMenuIfNeeded()) |
| 299 return; | 299 return; |
| 300 | 300 |
| 301 // Otherwise, no other menu is showing, and we can proceed normally. | 301 // Otherwise, no other menu is showing, and we can proceed normally. |
| 302 DoShowContextMenu(source_type); | 302 DoShowContextMenu(source_type); |
| 303 } | 303 } |
| 304 | 304 |
| 305 gfx::Point ToolbarActionView::CalculateInkDropCenter() const { | |
| 306 return GetLocalBounds().CenterPoint(); | |
| 307 } | |
| 308 | |
| 309 void ToolbarActionView::DoShowContextMenu( | 305 void ToolbarActionView::DoShowContextMenu( |
| 310 ui::MenuSourceType source_type) { | 306 ui::MenuSourceType source_type) { |
| 311 ui::MenuModel* context_menu_model = view_controller_->GetContextMenu(); | 307 ui::MenuModel* context_menu_model = view_controller_->GetContextMenu(); |
| 312 // It's possible the action doesn't have a context menu. | 308 // It's possible the action doesn't have a context menu. |
| 313 if (!context_menu_model) | 309 if (!context_menu_model) |
| 314 return; | 310 return; |
| 315 | 311 |
| 316 DCHECK(visible()); // We should never show a context menu for a hidden item. | 312 DCHECK(visible()); // We should never show a context menu for a hidden item. |
| 317 DCHECK(!context_menu_owner); | 313 DCHECK(!context_menu_owner); |
| 318 | 314 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 if (menu_controller->in_nested_run()) { | 367 if (menu_controller->in_nested_run()) { |
| 372 // There is another menu showing. Close the outermost menu (since we are | 368 // There is another menu showing. Close the outermost menu (since we are |
| 373 // shown in the same menu, we don't want to close the whole thing). | 369 // shown in the same menu, we don't want to close the whole thing). |
| 374 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST); | 370 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST); |
| 375 return true; | 371 return true; |
| 376 } | 372 } |
| 377 } | 373 } |
| 378 | 374 |
| 379 return false; | 375 return false; |
| 380 } | 376 } |
| OLD | NEW |