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

Side by Side Diff: chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.cc

Issue 2718563008: mash: Use mojo for ShelfItemDelegate and [app] MenuItem. (Closed)
Patch Set: Address comments. 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
OLDNEW
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/ash/launcher/app_window_launcher_item_controller.h" 5 #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/wm/window_util.h" 9 #include "ash/wm/window_util.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 ui::BaseWindow* app_window = GetAppWindow(window); 67 ui::BaseWindow* app_window = GetAppWindow(window);
68 if (app_window) 68 if (app_window)
69 last_active_window_ = app_window; 69 last_active_window_ = app_window;
70 } 70 }
71 71
72 AppWindowLauncherItemController* 72 AppWindowLauncherItemController*
73 AppWindowLauncherItemController::AsAppWindowLauncherItemController() { 73 AppWindowLauncherItemController::AsAppWindowLauncherItemController() {
74 return this; 74 return this;
75 } 75 }
76 76
77 ash::ShelfAction AppWindowLauncherItemController::ItemSelected( 77 void AppWindowLauncherItemController::ItemSelected(
78 ui::EventType event_type, 78 std::unique_ptr<ui::Event> event,
79 int event_flags,
80 int64_t display_id, 79 int64_t display_id,
81 ash::ShelfLaunchSource source) { 80 ash::ShelfLaunchSource source,
82 if (windows_.empty()) 81 const ItemSelectedCallback& callback) {
83 return ash::SHELF_ACTION_NONE; 82 if (windows_.empty()) {
83 callback.Run(ash::SHELF_ACTION_NONE,
84 std::vector<ash::mojom::MenuItemPtr>());
85 return;
86 }
84 87
85 ui::BaseWindow* window_to_show = 88 ui::BaseWindow* window_to_show =
86 last_active_window_ ? last_active_window_ : windows_.front(); 89 last_active_window_ ? last_active_window_ : windows_.front();
87 // If the event was triggered by a keystroke, we try to advance to the next 90 // If the event was triggered by a keystroke, we try to advance to the next
88 // item if the window we are trying to activate is already active. 91 // item if the window we are trying to activate is already active.
89 if (windows_.size() >= 1 && window_to_show->IsActive() && 92 ash::ShelfAction action = ash::SHELF_ACTION_NONE;
90 event_type == ui::ET_KEY_RELEASED) { 93 if (windows_.size() >= 1 && window_to_show->IsActive() && event &&
91 return ActivateOrAdvanceToNextAppWindow(window_to_show); 94 event->type() == ui::ET_KEY_RELEASED) {
95 action = ActivateOrAdvanceToNextAppWindow(window_to_show);
96 } else {
97 action = ShowAndActivateOrMinimize(window_to_show);
92 } 98 }
93 99
94 return ShowAndActivateOrMinimize(window_to_show); 100 callback.Run(action, GetAppMenuItems(event ? event->flags() : ui::EF_NONE));
95 }
96
97 ash::ShelfAppMenuItemList AppWindowLauncherItemController::GetAppMenuItems(
98 int event_flags) {
99 // Return an empty item list to avoid showing an application menu.
100 return ash::ShelfAppMenuItemList();
101 } 101 }
102 102
103 void AppWindowLauncherItemController::ExecuteCommand(uint32_t command_id, 103 void AppWindowLauncherItemController::ExecuteCommand(uint32_t command_id,
104 int event_flags) { 104 int32_t event_flags) {
105 // This delegate does not support showing an application menu. 105 // This delegate does not support showing an application menu.
106 NOTIMPLEMENTED(); 106 NOTIMPLEMENTED();
107 } 107 }
108 108
109 void AppWindowLauncherItemController::Close() { 109 void AppWindowLauncherItemController::Close() {
110 // Note: Closing windows may affect the contents of app_windows_. 110 // Note: Closing windows may affect the contents of app_windows_.
111 WindowList windows_to_close = windows_; 111 WindowList windows_to_close = windows_;
112 for (auto* window : windows_) 112 for (auto* window : windows_)
113 window->Close(); 113 window->Close();
114 } 114 }
(...skipping 20 matching lines...) Expand all
135 status = ash::STATUS_RUNNING; 135 status = ash::STATUS_RUNNING;
136 } 136 }
137 launcher_controller()->SetItemStatus(shelf_id(), status); 137 launcher_controller()->SetItemStatus(shelf_id(), status);
138 } 138 }
139 } 139 }
140 140
141 ash::ShelfAction AppWindowLauncherItemController::ShowAndActivateOrMinimize( 141 ash::ShelfAction AppWindowLauncherItemController::ShowAndActivateOrMinimize(
142 ui::BaseWindow* app_window) { 142 ui::BaseWindow* app_window) {
143 // Either show or minimize windows when shown from the launcher. 143 // Either show or minimize windows when shown from the launcher.
144 return launcher_controller()->ActivateWindowOrMinimizeIfActive( 144 return launcher_controller()->ActivateWindowOrMinimizeIfActive(
145 app_window, GetAppMenuItems(0).size() == 1); 145 app_window, GetAppMenuItems(ui::EF_NONE).size() == 1);
146 } 146 }
147 147
148 ash::ShelfAction 148 ash::ShelfAction
149 AppWindowLauncherItemController::ActivateOrAdvanceToNextAppWindow( 149 AppWindowLauncherItemController::ActivateOrAdvanceToNextAppWindow(
150 ui::BaseWindow* window_to_show) { 150 ui::BaseWindow* window_to_show) {
151 WindowList::iterator i( 151 WindowList::iterator i(
152 std::find(windows_.begin(), windows_.end(), window_to_show)); 152 std::find(windows_.begin(), windows_.end(), window_to_show));
153 if (i != windows_.end()) { 153 if (i != windows_.end()) {
154 if (++i != windows_.end()) 154 if (++i != windows_.end())
155 window_to_show = *i; 155 window_to_show = *i;
156 else 156 else
157 window_to_show = windows_.front(); 157 window_to_show = windows_.front();
158 } 158 }
159 if (window_to_show->IsActive()) { 159 if (window_to_show->IsActive()) {
160 // Coming here, only a single window is active. For keyboard activations 160 // Coming here, only a single window is active. For keyboard activations
161 // the window gets animated. 161 // the window gets animated.
162 AnimateWindow(window_to_show->GetNativeWindow(), 162 AnimateWindow(window_to_show->GetNativeWindow(),
163 wm::WINDOW_ANIMATION_TYPE_BOUNCE); 163 wm::WINDOW_ANIMATION_TYPE_BOUNCE);
164 } else { 164 } else {
165 return ShowAndActivateOrMinimize(window_to_show); 165 return ShowAndActivateOrMinimize(window_to_show);
166 } 166 }
167 return ash::SHELF_ACTION_NONE; 167 return ash::SHELF_ACTION_NONE;
168 } 168 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698