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

Side by Side Diff: ash/common/wm/overview/window_selector.cc

Issue 2401473002: [ash-md] Erases the pre-MD code path for Overview Mode (Closed)
Patch Set: [ash-md] Erases the pre-MD code path for Overview Mode Created 4 years, 2 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 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 "ash/common/wm/overview/window_selector.h" 5 #include "ash/common/wm/overview/window_selector.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "ash/common/accessibility_delegate.h" 13 #include "ash/common/accessibility_delegate.h"
14 #include "ash/common/accessibility_types.h" 14 #include "ash/common/accessibility_types.h"
15 #include "ash/common/material_design/material_design_controller.h"
16 #include "ash/common/metrics/user_metrics_action.h" 15 #include "ash/common/metrics/user_metrics_action.h"
17 #include "ash/common/shelf/wm_shelf.h" 16 #include "ash/common/shelf/wm_shelf.h"
18 #include "ash/common/shell_window_ids.h" 17 #include "ash/common/shell_window_ids.h"
19 #include "ash/common/wm/mru_window_tracker.h" 18 #include "ash/common/wm/mru_window_tracker.h"
20 #include "ash/common/wm/overview/window_grid.h" 19 #include "ash/common/wm/overview/window_grid.h"
21 #include "ash/common/wm/overview/window_selector_delegate.h" 20 #include "ash/common/wm/overview/window_selector_delegate.h"
22 #include "ash/common/wm/overview/window_selector_item.h" 21 #include "ash/common/wm/overview/window_selector_item.h"
23 #include "ash/common/wm/panels/panel_layout_manager.h" 22 #include "ash/common/wm/panels/panel_layout_manager.h"
24 #include "ash/common/wm/switchable_windows.h" 23 #include "ash/common/wm/switchable_windows.h"
25 #include "ash/common/wm/window_state.h" 24 #include "ash/common/wm/window_state.h"
(...skipping 17 matching lines...) Expand all
43 #include "ui/gfx/vector_icons_public.h" 42 #include "ui/gfx/vector_icons_public.h"
44 #include "ui/views/border.h" 43 #include "ui/views/border.h"
45 #include "ui/views/controls/image_view.h" 44 #include "ui/views/controls/image_view.h"
46 #include "ui/views/controls/textfield/textfield.h" 45 #include "ui/views/controls/textfield/textfield.h"
47 #include "ui/views/layout/box_layout.h" 46 #include "ui/views/layout/box_layout.h"
48 47
49 namespace ash { 48 namespace ash {
50 49
51 namespace { 50 namespace {
52 51
53 // The proportion of screen width that the text filter takes.
54 const float kTextFilterScreenProportion = 0.25;
55
56 // The amount of padding surrounding the text in the text filtering textbox. 52 // The amount of padding surrounding the text in the text filtering textbox.
57 const int kTextFilterHorizontalPadding = 8; 53 const int kTextFilterHorizontalPadding = 10;
58 const int kTextFilterHorizontalPaddingMD = 10;
59
60 // The distance between the top of the screen and the top edge of the
61 // text filtering textbox.
62 const int kTextFilterDistanceFromTop = 32;
63 54
64 // The height of the text filtering textbox. 55 // The height of the text filtering textbox.
65 const int kTextFilterHeight = 32; 56 const int kTextFilterHeight = 40;
66 const int kTextFilterHeightMD = 40;
67 57
68 // Distance from top of overview to the top of text filtering textbox as a 58 // Distance from top of overview to the top of text filtering textbox as a
69 // proportion of the total overview area with Material Design. 59 // proportion of the total overview area.
70 const float kTextFilterTopScreenProportion = 0.02f; 60 const float kTextFilterTopScreenProportion = 0.02f;
71 61
72 // Width of the text filter area with Material Design. 62 // Width of the text filter area.
73 const int kTextFilterWidthMD = 280; 63 const int kTextFilterWidth = 280;
74 64
75 // The font style used for text filtering textbox. 65 // The font style used for text filtering textbox.
76 static const ui::ResourceBundle::FontStyle kTextFilterFontStyle = 66 static const ui::ResourceBundle::FontStyle kTextFilterFontStyle =
77 ui::ResourceBundle::FontStyle::MediumFont;
78 static const ui::ResourceBundle::FontStyle kTextFilterFontStyleMD =
79 ui::ResourceBundle::FontStyle::BaseFont; 67 ui::ResourceBundle::FontStyle::BaseFont;
80 68
81 // The color of the text and its background in the text filtering textbox. 69 // The color of the text and its background in the text filtering textbox.
82 const SkColor kTextFilterTextColor = SK_ColorWHITE; 70 const SkColor kTextFilterTextColor = SkColorSetARGB(222, 0, 0, 0);
83 const SkColor kTextFilterTextColorMD = SkColorSetARGB(222, 0, 0, 0); 71 const SkColor kTextFilterBackgroundColor = SK_ColorWHITE;
84 const SkColor kTextFilterBackgroundColor = SkColorSetARGB(180, 0, 0, 0);
85 const SkColor kTextFilterBackgroundColorMD = SK_ColorWHITE;
86 72
87 // The color or search icon with Material Design. 73 // The color or search icon.
88 const SkColor kTextFilterIconColorMD = SkColorSetARGB(138, 0, 0, 0); 74 const SkColor kTextFilterIconColor = SkColorSetARGB(138, 0, 0, 0);
89 75
90 // The size of search icon with Material Design. 76 // The size of search icon.
91 const int kTextFilterIconSize = 20; 77 const int kTextFilterIconSize = 20;
92 78
93 // The radius used for the rounded corners on the text filtering textbox. 79 // The radius used for the rounded corners on the text filtering textbox.
94 const int kTextFilterCornerRadius = 1; 80 const int kTextFilterCornerRadius = 2;
95 const int kTextFilterCornerRadiusMD = 2;
96 81
97 // A comparator for locating a grid with a given root window. 82 // A comparator for locating a grid with a given root window.
98 struct RootWindowGridComparator { 83 struct RootWindowGridComparator {
99 explicit RootWindowGridComparator(const WmWindow* root_window) 84 explicit RootWindowGridComparator(const WmWindow* root_window)
100 : root_window_(root_window) {} 85 : root_window_(root_window) {}
101 86
102 bool operator()(const std::unique_ptr<WindowGrid>& grid) const { 87 bool operator()(const std::unique_ptr<WindowGrid>& grid) const {
103 return grid->root_window() == root_window_; 88 return grid->root_window() == root_window_;
104 } 89 }
105 90
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 DISALLOW_COPY_AND_ASSIGN(RoundedContainerView); 149 DISALLOW_COPY_AND_ASSIGN(RoundedContainerView);
165 }; 150 };
166 151
167 // Triggers a shelf visibility update on all root window controllers. 152 // Triggers a shelf visibility update on all root window controllers.
168 void UpdateShelfVisibility() { 153 void UpdateShelfVisibility() {
169 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) 154 for (WmWindow* root : WmShell::Get()->GetAllRootWindows())
170 WmShelf::ForWindow(root)->UpdateVisibilityState(); 155 WmShelf::ForWindow(root)->UpdateVisibilityState();
171 } 156 }
172 157
173 gfx::Rect GetTextFilterPosition(WmWindow* root_window) { 158 gfx::Rect GetTextFilterPosition(WmWindow* root_window) {
174 if (ash::MaterialDesignController::IsOverviewMaterial()) { 159 gfx::Rect total_bounds = root_window->ConvertRectToScreen(
175 gfx::Rect total_bounds = 160 wm::GetDisplayWorkAreaBoundsInParent(root_window->GetChildByShellWindowId(
176 root_window->ConvertRectToScreen(wm::GetDisplayWorkAreaBoundsInParent( 161 kShellWindowId_DefaultContainer)));
177 root_window->GetChildByShellWindowId(
178 kShellWindowId_DefaultContainer)));
179 return gfx::Rect(0.5 * (total_bounds.width() -
180 std::min(kTextFilterWidthMD, total_bounds.width())),
181 total_bounds.y() +
182 total_bounds.height() * kTextFilterTopScreenProportion,
183 std::min(kTextFilterWidthMD, total_bounds.width()),
184 kTextFilterHeightMD);
185 }
186 return gfx::Rect( 162 return gfx::Rect(
187 0.5 * root_window->GetBounds().width() * 163 0.5 * (total_bounds.width() -
188 (1 - kTextFilterScreenProportion), 164 std::min(kTextFilterWidth, total_bounds.width())),
189 kTextFilterDistanceFromTop, 165 total_bounds.y() + total_bounds.height() * kTextFilterTopScreenProportion,
190 root_window->GetBounds().width() * kTextFilterScreenProportion, 166 std::min(kTextFilterWidth, total_bounds.width()), kTextFilterHeight);
191 kTextFilterHeight);
192 } 167 }
193 168
194 // Initializes the text filter on the top of the main root window and requests 169 // Initializes the text filter on the top of the main root window and requests
195 // focus on its textfield. With Material Design uses |image| to place an icon 170 // focus on its textfield. Uses |image| to place an icon to the left of the text
196 // to the left of the text field. 171 // field.
197 views::Widget* CreateTextFilter(views::TextfieldController* controller, 172 views::Widget* CreateTextFilter(views::TextfieldController* controller,
198 WmWindow* root_window, 173 WmWindow* root_window,
199 const gfx::ImageSkia& image, 174 const gfx::ImageSkia& image,
200 int* text_filter_bottom) { 175 int* text_filter_bottom) {
201 views::Widget* widget = new views::Widget; 176 views::Widget* widget = new views::Widget;
202 views::Widget::InitParams params; 177 views::Widget::InitParams params;
203 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; 178 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS;
204 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 179 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
205 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 180 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
206 params.accept_events = true; 181 params.accept_events = true;
207 params.bounds = GetTextFilterPosition(root_window); 182 params.bounds = GetTextFilterPosition(root_window);
208 params.name = "OverviewModeTextFilter"; 183 params.name = "OverviewModeTextFilter";
209 *text_filter_bottom = params.bounds.bottom(); 184 *text_filter_bottom = params.bounds.bottom();
210 root_window->GetRootWindowController()->ConfigureWidgetInitParamsForContainer( 185 root_window->GetRootWindowController()->ConfigureWidgetInitParamsForContainer(
211 widget, kShellWindowId_StatusContainer, &params); 186 widget, kShellWindowId_StatusContainer, &params);
212 widget->Init(params); 187 widget->Init(params);
213 188
214 // Use |container| to specify the padding surrounding the text and to give 189 // Use |container| to specify the padding surrounding the text and to give
215 // the textfield rounded corners. 190 // the textfield rounded corners.
216 const bool material = ash::MaterialDesignController::IsOverviewMaterial(); 191 views::View* container = new RoundedContainerView(kTextFilterCornerRadius,
217 views::View* container = new RoundedContainerView( 192 kTextFilterBackgroundColor);
218 material ? kTextFilterCornerRadiusMD : kTextFilterCornerRadius,
219 material ? kTextFilterBackgroundColorMD : kTextFilterBackgroundColor);
220 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 193 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
221 const ui::ResourceBundle::FontStyle font_style =
222 material ? kTextFilterFontStyleMD : kTextFilterFontStyle;
223 const int text_height = 194 const int text_height =
224 std::max(kTextFilterIconSize, bundle.GetFontList(font_style).GetHeight()); 195 std::max(kTextFilterIconSize,
196 bundle.GetFontList(kTextFilterFontStyle).GetHeight());
225 DCHECK(text_height); 197 DCHECK(text_height);
226 const int vertical_padding = (params.bounds.height() - text_height) / 2; 198 const int vertical_padding = (params.bounds.height() - text_height) / 2;
227 const int horizontal_padding = 199 views::BoxLayout* layout = new views::BoxLayout(
228 material ? kTextFilterHorizontalPaddingMD : kTextFilterHorizontalPadding; 200 views::BoxLayout::kHorizontal, kTextFilterHorizontalPadding,
229 views::BoxLayout* layout = 201 vertical_padding, kTextFilterHorizontalPadding);
230 new views::BoxLayout(views::BoxLayout::kHorizontal, horizontal_padding,
231 vertical_padding, horizontal_padding);
232 container->SetLayoutManager(layout); 202 container->SetLayoutManager(layout);
233 203
234 views::Textfield* textfield = new views::Textfield; 204 views::Textfield* textfield = new views::Textfield;
235 textfield->set_controller(controller); 205 textfield->set_controller(controller);
236 textfield->SetBorder(views::Border::NullBorder()); 206 textfield->SetBorder(views::Border::NullBorder());
237 if (material) { 207 textfield->SetBackgroundColor(kTextFilterBackgroundColor);
238 textfield->SetBackgroundColor(kTextFilterBackgroundColorMD); 208 textfield->SetTextColor(kTextFilterTextColor);
239 textfield->SetTextColor(kTextFilterTextColorMD); 209 views::ImageView* image_view = new views::ImageView;
240 views::ImageView* image_view = new views::ImageView; 210 image_view->SetImage(image);
241 image_view->SetImage(image); 211 container->AddChildView(image_view);
242 container->AddChildView(image_view); 212 textfield->SetFontList(bundle.GetFontList(kTextFilterFontStyle));
243 } else {
244 textfield->SetBackgroundColor(SK_ColorTRANSPARENT);
245 textfield->SetTextColor(kTextFilterTextColor);
246 }
247 textfield->SetFontList(bundle.GetFontList(font_style));
248 container->AddChildView(textfield); 213 container->AddChildView(textfield);
249 layout->SetFlexForView(textfield, 1); 214 layout->SetFlexForView(textfield, 1);
250 widget->SetContentsView(container); 215 widget->SetContentsView(container);
251 216
252 // The textfield initially contains no text, so shift its position to be 217 // The textfield initially contains no text, so shift its position to be
253 // outside the visible bounds of the screen. 218 // outside the visible bounds of the screen.
254 gfx::Transform transform; 219 gfx::Transform transform;
255 transform.Translate(0, -params.bounds.bottom()); 220 transform.Translate(0, -params.bounds.bottom());
256 WmLookup::Get()->GetWindowForWidget(widget)->SetTransform(transform); 221 WmLookup::Get()->GetWindowForWidget(widget)->SetTransform(transform);
257 widget->Show(); 222 widget->Show();
258 textfield->RequestFocus(); 223 textfield->RequestFocus();
259 224
260 return widget; 225 return widget;
261 } 226 }
262 227
263 } // namespace 228 } // namespace
264 229
265 // static 230 // static
266 bool WindowSelector::IsSelectable(WmWindow* window) { 231 bool WindowSelector::IsSelectable(WmWindow* window) {
267 wm::WindowState* state = window->GetWindowState(); 232 wm::WindowState* state = window->GetWindowState();
268 if (!ash::MaterialDesignController::IsOverviewMaterial() &&
269 (state->GetStateType() == wm::WINDOW_STATE_TYPE_DOCKED ||
270 state->GetStateType() == wm::WINDOW_STATE_TYPE_DOCKED_MINIMIZED)) {
271 return false;
272 }
273 return state->IsUserPositionable(); 233 return state->IsUserPositionable();
274 } 234 }
275 235
276 WindowSelector::WindowSelector(WindowSelectorDelegate* delegate) 236 WindowSelector::WindowSelector(WindowSelectorDelegate* delegate)
277 : delegate_(delegate), 237 : delegate_(delegate),
278 restore_focus_window_(WmShell::Get()->GetFocusedWindow()), 238 restore_focus_window_(WmShell::Get()->GetFocusedWindow()),
279 ignore_activations_(false), 239 ignore_activations_(false),
280 selected_grid_index_(0), 240 selected_grid_index_(0),
281 overview_start_time_(base::Time::Now()), 241 overview_start_time_(base::Time::Now()),
282 num_key_presses_(0), 242 num_key_presses_(0),
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 &restoring_minimized_windows_, true); 306 &restoring_minimized_windows_, true);
347 307
348 // Do not call PrepareForOverview until all items are added to window_list_ 308 // Do not call PrepareForOverview until all items are added to window_list_
349 // as we don't want to cause any window updates until all windows in 309 // as we don't want to cause any window updates until all windows in
350 // overview are observed. See http://crbug.com/384495. 310 // overview are observed. See http://crbug.com/384495.
351 for (std::unique_ptr<WindowGrid>& window_grid : grid_list_) { 311 for (std::unique_ptr<WindowGrid>& window_grid : grid_list_) {
352 window_grid->PrepareForOverview(); 312 window_grid->PrepareForOverview();
353 window_grid->PositionWindows(true); 313 window_grid->PositionWindows(true);
354 } 314 }
355 315
356 if (ash::MaterialDesignController::IsOverviewMaterial()) { 316 search_image_ =
357 search_image_ = 317 gfx::CreateVectorIcon(gfx::VectorIconId::OMNIBOX_SEARCH,
358 gfx::CreateVectorIcon(gfx::VectorIconId::OMNIBOX_SEARCH, 318 kTextFilterIconSize, kTextFilterIconColor);
359 kTextFilterIconSize, kTextFilterIconColorMD);
360 }
361 WmWindow* root_window = shell->GetPrimaryRootWindow(); 319 WmWindow* root_window = shell->GetPrimaryRootWindow();
362 text_filter_widget_.reset(CreateTextFilter(this, root_window, search_image_, 320 text_filter_widget_.reset(CreateTextFilter(this, root_window, search_image_,
363 &text_filter_bottom_)); 321 &text_filter_bottom_));
364 } 322 }
365 323
366 DCHECK(!grid_list_.empty()); 324 DCHECK(!grid_list_.empty());
367 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.Items", num_items_); 325 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.Items", num_items_);
368 326
369 shell->AddActivationObserver(this); 327 shell->AddActivationObserver(this);
370 328
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 for (size_t i = 0; i <= grid_list_.size() && 676 for (size_t i = 0; i <= grid_list_.size() &&
719 grid_list_[selected_grid_index_]->Move(direction, animate); 677 grid_list_[selected_grid_index_]->Move(direction, animate);
720 i++) { 678 i++) {
721 selected_grid_index_ = 679 selected_grid_index_ =
722 (selected_grid_index_ + display_direction + grid_list_.size()) % 680 (selected_grid_index_ + display_direction + grid_list_.size()) %
723 grid_list_.size(); 681 grid_list_.size();
724 } 682 }
725 } 683 }
726 684
727 } // namespace ash 685 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698