Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(501)

Side by Side Diff: ash/common/shelf/shelf_view.cc

Issue 2726823003: Remove WmLookup. (Closed)
Patch Set: Clean up include and modify comment. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/common/shelf/shelf_tooltip_manager.cc ('k') | ash/common/shelf/shelf_widget.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ash/common/shelf/shelf_view.h" 5 #include "ash/common/shelf/shelf_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 9
10 #include "ash/common/ash_constants.h" 10 #include "ash/common/ash_constants.h"
11 #include "ash/common/drag_drop/drag_image_view.h" 11 #include "ash/common/drag_drop/drag_image_view.h"
12 #include "ash/common/scoped_root_window_for_new_windows.h" 12 #include "ash/common/scoped_root_window_for_new_windows.h"
13 #include "ash/common/shelf/app_list_button.h" 13 #include "ash/common/shelf/app_list_button.h"
14 #include "ash/common/shelf/overflow_bubble.h" 14 #include "ash/common/shelf/overflow_bubble.h"
15 #include "ash/common/shelf/overflow_bubble_view.h" 15 #include "ash/common/shelf/overflow_bubble_view.h"
16 #include "ash/common/shelf/overflow_button.h" 16 #include "ash/common/shelf/overflow_button.h"
17 #include "ash/common/shelf/shelf_application_menu_model.h" 17 #include "ash/common/shelf/shelf_application_menu_model.h"
18 #include "ash/common/shelf/shelf_button.h" 18 #include "ash/common/shelf/shelf_button.h"
19 #include "ash/common/shelf/shelf_constants.h" 19 #include "ash/common/shelf/shelf_constants.h"
20 #include "ash/common/shelf/shelf_delegate.h" 20 #include "ash/common/shelf/shelf_delegate.h"
21 #include "ash/common/shelf/shelf_model.h" 21 #include "ash/common/shelf/shelf_model.h"
22 #include "ash/common/shelf/shelf_widget.h" 22 #include "ash/common/shelf/shelf_widget.h"
23 #include "ash/common/shelf/wm_shelf.h" 23 #include "ash/common/shelf/wm_shelf.h"
24 #include "ash/common/shell_delegate.h" 24 #include "ash/common/shell_delegate.h"
25 #include "ash/common/wm/root_window_finder.h" 25 #include "ash/common/wm/root_window_finder.h"
26 #include "ash/common/wm_lookup.h"
27 #include "ash/common/wm_shell.h" 26 #include "ash/common/wm_shell.h"
28 #include "ash/common/wm_window.h" 27 #include "ash/common/wm_window.h"
29 #include "ash/strings/grit/ash_strings.h" 28 #include "ash/strings/grit/ash_strings.h"
30 #include "base/auto_reset.h" 29 #include "base/auto_reset.h"
31 #include "base/memory/ptr_util.h" 30 #include "base/memory/ptr_util.h"
32 #include "base/metrics/histogram_macros.h" 31 #include "base/metrics/histogram_macros.h"
33 #include "ui/accessibility/ax_node_data.h" 32 #include "ui/accessibility/ax_node_data.h"
34 #include "ui/base/l10n/l10n_util.h" 33 #include "ui/base/l10n/l10n_util.h"
35 #include "ui/base/models/simple_menu_model.h" 34 #include "ui/base/models/simple_menu_model.h"
36 #include "ui/compositor/layer.h" 35 #include "ui/compositor/layer.h"
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 // None of the checks in ShouldEventActivateButton() affects overflow button. 442 // None of the checks in ShouldEventActivateButton() affects overflow button.
444 // So, it is safe to be checked after handling overflow button. 443 // So, it is safe to be checked after handling overflow button.
445 if (!ShouldEventActivateButton(sender, event)) 444 if (!ShouldEventActivateButton(sender, event))
446 return; 445 return;
447 446
448 // Record the index for the last pressed shelf item. 447 // Record the index for the last pressed shelf item.
449 last_pressed_index_ = view_model_->GetIndexOfView(sender); 448 last_pressed_index_ = view_model_->GetIndexOfView(sender);
450 DCHECK_LT(-1, last_pressed_index_); 449 DCHECK_LT(-1, last_pressed_index_);
451 450
452 // Place new windows on the same display as the button. 451 // Place new windows on the same display as the button.
453 WmWindow* window = WmLookup::Get()->GetWindowForWidget(sender->GetWidget()); 452 WmWindow* window = WmWindow::Get(sender->GetWidget()->GetNativeWindow());
454 scoped_root_window_for_new_windows_.reset( 453 scoped_root_window_for_new_windows_.reset(
455 new ScopedRootWindowForNewWindows(window->GetRootWindow())); 454 new ScopedRootWindowForNewWindows(window->GetRootWindow()));
456 455
457 // Slow down activation animations if shift key is pressed. 456 // Slow down activation animations if shift key is pressed.
458 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> slowing_animations; 457 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> slowing_animations;
459 if (event.IsShiftDown()) { 458 if (event.IsShiftDown()) {
460 slowing_animations.reset(new ui::ScopedAnimationDurationScaleMode( 459 slowing_animations.reset(new ui::ScopedAnimationDurationScaleMode(
461 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); 460 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION));
462 } 461 }
463 462
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 } 521 }
523 522
524 void ShelfView::CreateDragIconProxy( 523 void ShelfView::CreateDragIconProxy(
525 const gfx::Point& location_in_screen_coordinates, 524 const gfx::Point& location_in_screen_coordinates,
526 const gfx::ImageSkia& icon, 525 const gfx::ImageSkia& icon,
527 views::View* replaced_view, 526 views::View* replaced_view,
528 const gfx::Vector2d& cursor_offset_from_center, 527 const gfx::Vector2d& cursor_offset_from_center,
529 float scale_factor) { 528 float scale_factor) {
530 drag_replaced_view_ = replaced_view; 529 drag_replaced_view_ = replaced_view;
531 WmWindow* root_window = 530 WmWindow* root_window =
532 WmLookup::Get() 531 WmWindow::Get(drag_replaced_view_->GetWidget()->GetNativeWindow())
533 ->GetWindowForWidget(drag_replaced_view_->GetWidget())
534 ->GetRootWindow(); 532 ->GetRootWindow();
535 drag_image_.reset(new DragImageView( 533 drag_image_.reset(new DragImageView(
536 root_window, ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE)); 534 root_window, ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE));
537 drag_image_->SetImage(icon); 535 drag_image_->SetImage(icon);
538 gfx::Size size = drag_image_->GetPreferredSize(); 536 gfx::Size size = drag_image_->GetPreferredSize();
539 size.set_width(size.width() * scale_factor); 537 size.set_width(size.width() * scale_factor);
540 size.set_height(size.height() * scale_factor); 538 size.set_height(size.height() * scale_factor);
541 drag_image_offset_ = gfx::Vector2d(size.width() / 2, size.height() / 2) + 539 drag_image_offset_ = gfx::Vector2d(size.width() / 2, size.height() / 2) +
542 cursor_offset_from_center; 540 cursor_offset_from_center;
543 gfx::Rect drag_image_bounds( 541 gfx::Rect drag_image_bounds(
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 bounds_animator_->StopAnimatingView(drag_view_); 1073 bounds_animator_->StopAnimatingView(drag_view_);
1076 } 1074 }
1077 1075
1078 bool ShelfView::HandleRipOffDrag(const ui::LocatedEvent& event) { 1076 bool ShelfView::HandleRipOffDrag(const ui::LocatedEvent& event) {
1079 int current_index = view_model_->GetIndexOfView(drag_view_); 1077 int current_index = view_model_->GetIndexOfView(drag_view_);
1080 DCHECK_NE(-1, current_index); 1078 DCHECK_NE(-1, current_index);
1081 std::string dragged_app_id = 1079 std::string dragged_app_id =
1082 delegate_->GetAppIDForShelfID(model_->items()[current_index].id); 1080 delegate_->GetAppIDForShelfID(model_->items()[current_index].id);
1083 1081
1084 gfx::Point screen_location = 1082 gfx::Point screen_location =
1085 WmLookup::Get() 1083 WmWindow::Get(GetWidget()->GetNativeWindow())
1086 ->GetWindowForWidget(GetWidget())
1087 ->GetRootWindow() 1084 ->GetRootWindow()
1088 ->ConvertPointToScreen(event.root_location()); 1085 ->ConvertPointToScreen(event.root_location());
1089 1086
1090 // To avoid ugly forwards and backwards flipping we use different constants 1087 // To avoid ugly forwards and backwards flipping we use different constants
1091 // for ripping off / re-inserting the items. 1088 // for ripping off / re-inserting the items.
1092 if (dragged_off_shelf_) { 1089 if (dragged_off_shelf_) {
1093 // If the shelf/overflow bubble bounds contains |screen_location| we insert 1090 // If the shelf/overflow bubble bounds contains |screen_location| we insert
1094 // the item back into the shelf. 1091 // the item back into the shelf.
1095 if (GetBoundsForDragInsertInScreen().Contains(screen_location)) { 1092 if (GetBoundsForDragInsertInScreen().Contains(screen_location)) {
1096 if (dragged_off_from_overflow_to_shelf_) { 1093 if (dragged_off_from_overflow_to_shelf_) {
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
1665 base::Bind(&ShelfView::OnMenuClosed, base::Unretained(this), ink_drop))); 1662 base::Bind(&ShelfView::OnMenuClosed, base::Unretained(this), ink_drop)));
1666 1663
1667 closing_event_time_ = base::TimeTicks(); 1664 closing_event_time_ = base::TimeTicks();
1668 int run_types = views::MenuRunner::ASYNC; 1665 int run_types = views::MenuRunner::ASYNC;
1669 if (context_menu) 1666 if (context_menu)
1670 run_types |= views::MenuRunner::CONTEXT_MENU; 1667 run_types |= views::MenuRunner::CONTEXT_MENU;
1671 launcher_menu_runner_.reset( 1668 launcher_menu_runner_.reset(
1672 new views::MenuRunner(menu_model_adapter_->CreateMenu(), run_types)); 1669 new views::MenuRunner(menu_model_adapter_->CreateMenu(), run_types));
1673 1670
1674 // Place new windows on the same display as the button that spawned the menu. 1671 // Place new windows on the same display as the button that spawned the menu.
1675 WmWindow* window = WmLookup::Get()->GetWindowForWidget(source->GetWidget()); 1672 WmWindow* window = WmWindow::Get(source->GetWidget()->GetNativeWindow());
1676 scoped_root_window_for_new_windows_.reset( 1673 scoped_root_window_for_new_windows_.reset(
1677 new ScopedRootWindowForNewWindows(window->GetRootWindow())); 1674 new ScopedRootWindowForNewWindows(window->GetRootWindow()));
1678 1675
1679 views::MenuAnchorPosition menu_alignment = views::MENU_ANCHOR_TOPLEFT; 1676 views::MenuAnchorPosition menu_alignment = views::MENU_ANCHOR_TOPLEFT;
1680 gfx::Rect anchor = gfx::Rect(click_point, gfx::Size()); 1677 gfx::Rect anchor = gfx::Rect(click_point, gfx::Size());
1681 1678
1682 if (!context_menu) { 1679 if (!context_menu) {
1683 // Application lists use a bubble. 1680 // Application lists use a bubble.
1684 // It is possible to invoke the menu while it is sliding into view. To cover 1681 // It is possible to invoke the menu while it is sliding into view. To cover
1685 // that case, the screen coordinates are offsetted by the animation delta. 1682 // that case, the screen coordinates are offsetted by the animation delta.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1773 1770
1774 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { 1771 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const {
1775 const gfx::Rect bounds = GetBoundsInScreen(); 1772 const gfx::Rect bounds = GetBoundsInScreen();
1776 int distance = wm_shelf_->SelectValueForShelfAlignment( 1773 int distance = wm_shelf_->SelectValueForShelfAlignment(
1777 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), 1774 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(),
1778 bounds.x() - coordinate.x()); 1775 bounds.x() - coordinate.x());
1779 return distance > 0 ? distance : 0; 1776 return distance > 0 ? distance : 0;
1780 } 1777 }
1781 1778
1782 } // namespace ash 1779 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/shelf/shelf_tooltip_manager.cc ('k') | ash/common/shelf/shelf_widget.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698