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

Side by Side Diff: ash/wm/overview/window_selector_item.cc

Issue 2035543004: Shuffles and renames ash/common/wm classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: random changes for chrome tests Created 4 years, 6 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/wm/overview/window_selector_item.h" 5 #include "ash/wm/overview/window_selector_item.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/common/shell_window_ids.h" 10 #include "ash/common/shell_window_ids.h"
11 #include "ash/common/wm/window_state.h" 11 #include "ash/common/wm/window_state.h"
12 #include "ash/common/wm/wm_lookup.h" 12 #include "ash/common/wm_lookup.h"
13 #include "ash/common/wm/wm_root_window_controller.h" 13 #include "ash/common/wm_root_window_controller.h"
14 #include "ash/common/wm/wm_window.h" 14 #include "ash/common/wm_window.h"
15 #include "ash/common/wm/wm_window_property.h" 15 #include "ash/common/wm_window_property.h"
16 #include "ash/material_design/material_design_controller.h" 16 #include "ash/material_design/material_design_controller.h"
17 #include "ash/wm/overview/overview_animation_type.h" 17 #include "ash/wm/overview/overview_animation_type.h"
18 #include "ash/wm/overview/scoped_overview_animation_settings.h" 18 #include "ash/wm/overview/scoped_overview_animation_settings.h"
19 #include "ash/wm/overview/scoped_overview_animation_settings_factory.h" 19 #include "ash/wm/overview/scoped_overview_animation_settings_factory.h"
20 #include "ash/wm/overview/scoped_transform_overview_window.h" 20 #include "ash/wm/overview/scoped_transform_overview_window.h"
21 #include "ash/wm/overview/window_selector.h" 21 #include "ash/wm/overview/window_selector.h"
22 #include "ash/wm/overview/window_selector_controller.h" 22 #include "ash/wm/overview/window_selector_controller.h"
23 #include "base/auto_reset.h" 23 #include "base/auto_reset.h"
24 #include "base/strings/string_util.h" 24 #include "base/strings/string_util.h"
25 #include "base/strings/utf_string_conversions.h" 25 #include "base/strings/utf_string_conversions.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 // Amount of blur applied to the label shadow 66 // Amount of blur applied to the label shadow
67 static const int kShadowBlur = 10; 67 static const int kShadowBlur = 10;
68 68
69 // Opacity for dimmed items. 69 // Opacity for dimmed items.
70 static const float kDimmedItemOpacity = 0.5f; 70 static const float kDimmedItemOpacity = 0.5f;
71 71
72 // Calculates the |window| bounds after being transformed to the selector's 72 // Calculates the |window| bounds after being transformed to the selector's
73 // space. With Material Design at most |title_height| is reserved above the 73 // space. With Material Design at most |title_height| is reserved above the
74 // |window|. The returned Rect is in virtual screen coordinates. 74 // |window|. The returned Rect is in virtual screen coordinates.
75 gfx::Rect GetTransformedBounds(wm::WmWindow* window, int title_height) { 75 gfx::Rect GetTransformedBounds(WmWindow* window, int title_height) {
76 gfx::RectF bounds( 76 gfx::RectF bounds(
77 window->GetRootWindow()->ConvertRectToScreen(window->GetTargetBounds())); 77 window->GetRootWindow()->ConvertRectToScreen(window->GetTargetBounds()));
78 gfx::Transform new_transform = TransformAboutPivot( 78 gfx::Transform new_transform = TransformAboutPivot(
79 gfx::Point(bounds.x(), bounds.y()), window->GetTargetTransform()); 79 gfx::Point(bounds.x(), bounds.y()), window->GetTargetTransform());
80 new_transform.TransformRect(&bounds); 80 new_transform.TransformRect(&bounds);
81 81
82 // With Material Design the preview title is shown above the preview window. 82 // With Material Design the preview title is shown above the preview window.
83 // Hide the window header for apps or browser windows with no tabs (web apps) 83 // Hide the window header for apps or browser windows with no tabs (web apps)
84 // to avoid showing both the window header and the preview title. 84 // to avoid showing both the window header and the preview title.
85 if (ash::MaterialDesignController::IsOverviewMaterial()) { 85 if (ash::MaterialDesignController::IsOverviewMaterial()) {
86 gfx::RectF header_bounds(bounds); 86 gfx::RectF header_bounds(bounds);
87 header_bounds.set_height( 87 header_bounds.set_height(
88 std::min(window->GetIntProperty(wm::WmWindowProperty::TOP_VIEW_INSET), 88 std::min(window->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET),
89 title_height)); 89 title_height));
90 new_transform.TransformRect(&header_bounds); 90 new_transform.TransformRect(&header_bounds);
91 bounds.Inset(0, header_bounds.height(), 0, 0); 91 bounds.Inset(0, header_bounds.height(), 0, 0);
92 } 92 }
93 return ToEnclosingRect(bounds); 93 return ToEnclosingRect(bounds);
94 } 94 }
95 95
96 // Convenience method to fade in a Window with predefined animation settings. 96 // Convenience method to fade in a Window with predefined animation settings.
97 // Note: The fade in animation will occur after a delay where the delay is how 97 // Note: The fade in animation will occur after a delay where the delay is how
98 // long the lay out animations take. 98 // long the lay out animations take.
99 void SetupFadeInAfterLayout(views::Widget* widget) { 99 void SetupFadeInAfterLayout(views::Widget* widget) {
100 wm::WmWindow* window = wm::WmLookup::Get()->GetWindowForWidget(widget); 100 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget);
101 window->SetOpacity(0.0f); 101 window->SetOpacity(0.0f);
102 std::unique_ptr<ScopedOverviewAnimationSettings> 102 std::unique_ptr<ScopedOverviewAnimationSettings>
103 scoped_overview_animation_settings = 103 scoped_overview_animation_settings =
104 ScopedOverviewAnimationSettingsFactory::Get() 104 ScopedOverviewAnimationSettingsFactory::Get()
105 ->CreateOverviewAnimationSettings( 105 ->CreateOverviewAnimationSettings(
106 OverviewAnimationType:: 106 OverviewAnimationType::
107 OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN, 107 OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN,
108 window); 108 window);
109 window->SetOpacity(1.0f); 109 window->SetOpacity(1.0f);
110 } 110 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 147
148 gfx::Rect WindowSelectorItem::OverviewLabelButton::GetChildAreaBounds() { 148 gfx::Rect WindowSelectorItem::OverviewLabelButton::GetChildAreaBounds() {
149 gfx::Rect bounds = GetLocalBounds(); 149 gfx::Rect bounds = GetLocalBounds();
150 if (ash::MaterialDesignController::IsOverviewMaterial()) 150 if (ash::MaterialDesignController::IsOverviewMaterial())
151 bounds.Inset(kHorizontalLabelPaddingMD, 0, kHorizontalLabelPaddingMD, 0); 151 bounds.Inset(kHorizontalLabelPaddingMD, 0, kHorizontalLabelPaddingMD, 0);
152 else 152 else
153 bounds.Inset(0, top_padding_, 0, 0); 153 bounds.Inset(0, top_padding_, 0, 0);
154 return bounds; 154 return bounds;
155 } 155 }
156 156
157 WindowSelectorItem::WindowSelectorItem(wm::WmWindow* window, 157 WindowSelectorItem::WindowSelectorItem(WmWindow* window,
158 WindowSelector* window_selector) 158 WindowSelector* window_selector)
159 : dimmed_(false), 159 : dimmed_(false),
160 root_window_(window->GetRootWindow()), 160 root_window_(window->GetRootWindow()),
161 transform_window_(window), 161 transform_window_(window),
162 in_bounds_update_(false), 162 in_bounds_update_(false),
163 window_label_button_view_(nullptr), 163 window_label_button_view_(nullptr),
164 close_button_(new OverviewCloseButton(this)), 164 close_button_(new OverviewCloseButton(this)),
165 window_selector_(window_selector) { 165 window_selector_(window_selector) {
166 const bool material = ash::MaterialDesignController::IsOverviewMaterial(); 166 const bool material = ash::MaterialDesignController::IsOverviewMaterial();
167 CreateWindowLabel(window->GetTitle()); 167 CreateWindowLabel(window->GetTitle());
(...skipping 15 matching lines...) Expand all
183 // Align the center of the button with position (0, 0) so that the 183 // Align the center of the button with position (0, 0) so that the
184 // translate transform does not need to take the button dimensions into 184 // translate transform does not need to take the button dimensions into
185 // account. 185 // account.
186 if (material) { 186 if (material) {
187 close_button_rect.set_x(-close_button_rect.width()); 187 close_button_rect.set_x(-close_button_rect.width());
188 close_button_rect.set_y(-close_button_rect.height()); 188 close_button_rect.set_y(-close_button_rect.height());
189 } else { 189 } else {
190 close_button_rect.set_x(-close_button_rect.width() / 2); 190 close_button_rect.set_x(-close_button_rect.width() / 2);
191 close_button_rect.set_y(-close_button_rect.height() / 2); 191 close_button_rect.set_y(-close_button_rect.height() / 2);
192 } 192 }
193 wm::WmLookup::Get() 193 WmLookup::Get()
194 ->GetWindowForWidget(&close_button_widget_) 194 ->GetWindowForWidget(&close_button_widget_)
195 ->SetBounds(close_button_rect); 195 ->SetBounds(close_button_rect);
196 196
197 GetWindow()->AddObserver(this); 197 GetWindow()->AddObserver(this);
198 } 198 }
199 199
200 WindowSelectorItem::~WindowSelectorItem() { 200 WindowSelectorItem::~WindowSelectorItem() {
201 GetWindow()->RemoveObserver(this); 201 GetWindow()->RemoveObserver(this);
202 } 202 }
203 203
204 wm::WmWindow* WindowSelectorItem::GetWindow() { 204 WmWindow* WindowSelectorItem::GetWindow() {
205 return transform_window_.window(); 205 return transform_window_.window();
206 } 206 }
207 207
208 void WindowSelectorItem::RestoreWindow() { 208 void WindowSelectorItem::RestoreWindow() {
209 transform_window_.RestoreWindow(); 209 transform_window_.RestoreWindow();
210 } 210 }
211 211
212 void WindowSelectorItem::ShowWindowOnExit() { 212 void WindowSelectorItem::ShowWindowOnExit() {
213 transform_window_.ShowWindowOnExit(); 213 transform_window_.ShowWindowOnExit();
214 } 214 }
215 215
216 void WindowSelectorItem::PrepareForOverview() { 216 void WindowSelectorItem::PrepareForOverview() {
217 transform_window_.PrepareForOverview(); 217 transform_window_.PrepareForOverview();
218 } 218 }
219 219
220 bool WindowSelectorItem::Contains(const wm::WmWindow* target) const { 220 bool WindowSelectorItem::Contains(const WmWindow* target) const {
221 return transform_window_.Contains(target); 221 return transform_window_.Contains(target);
222 } 222 }
223 223
224 void WindowSelectorItem::SetBounds(const gfx::Rect& target_bounds, 224 void WindowSelectorItem::SetBounds(const gfx::Rect& target_bounds,
225 OverviewAnimationType animation_type) { 225 OverviewAnimationType animation_type) {
226 if (in_bounds_update_) 226 if (in_bounds_update_)
227 return; 227 return;
228 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true); 228 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true);
229 target_bounds_ = target_bounds; 229 target_bounds_ = target_bounds;
230 230
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 void WindowSelectorItem::ButtonPressed(views::Button* sender, 268 void WindowSelectorItem::ButtonPressed(views::Button* sender,
269 const ui::Event& event) { 269 const ui::Event& event) {
270 if (sender == close_button_) { 270 if (sender == close_button_) {
271 transform_window_.Close(); 271 transform_window_.Close();
272 return; 272 return;
273 } 273 }
274 CHECK(sender == window_label_button_view_); 274 CHECK(sender == window_label_button_view_);
275 window_selector_->SelectWindow(transform_window_.window()); 275 window_selector_->SelectWindow(transform_window_.window());
276 } 276 }
277 277
278 void WindowSelectorItem::OnWindowDestroying(wm::WmWindow* window) { 278 void WindowSelectorItem::OnWindowDestroying(WmWindow* window) {
279 window->RemoveObserver(this); 279 window->RemoveObserver(this);
280 transform_window_.OnWindowDestroyed(); 280 transform_window_.OnWindowDestroyed();
281 } 281 }
282 282
283 void WindowSelectorItem::OnWindowTitleChanged(wm::WmWindow* window) { 283 void WindowSelectorItem::OnWindowTitleChanged(WmWindow* window) {
284 // TODO(flackr): Maybe add the new title to a vector of titles so that we can 284 // TODO(flackr): Maybe add the new title to a vector of titles so that we can
285 // filter any of the titles the window had while in the overview session. 285 // filter any of the titles the window had while in the overview session.
286 window_label_button_view_->SetText(window->GetTitle()); 286 window_label_button_view_->SetText(window->GetTitle());
287 UpdateCloseButtonAccessibilityName(); 287 UpdateCloseButtonAccessibilityName();
288 } 288 }
289 289
290 void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds, 290 void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds,
291 OverviewAnimationType animation_type) { 291 OverviewAnimationType animation_type) {
292 DCHECK(root_window_ == GetWindow()->GetRootWindow()); 292 DCHECK(root_window_ == GetWindow()->GetRootWindow());
293 gfx::Rect screen_rect = transform_window_.GetTargetBoundsInScreen(); 293 gfx::Rect screen_rect = transform_window_.GetTargetBoundsInScreen();
294 294
295 // Avoid division by zero by ensuring screen bounds is not empty. 295 // Avoid division by zero by ensuring screen bounds is not empty.
296 gfx::Size screen_size(screen_rect.size()); 296 gfx::Size screen_size(screen_rect.size());
297 screen_size.SetToMax(gfx::Size(1, 1)); 297 screen_size.SetToMax(gfx::Size(1, 1));
298 screen_rect.set_size(screen_size); 298 screen_rect.set_size(screen_size);
299 299
300 int top_view_inset = 0; 300 int top_view_inset = 0;
301 int title_height = 0; 301 int title_height = 0;
302 if (ash::MaterialDesignController::IsOverviewMaterial()) { 302 if (ash::MaterialDesignController::IsOverviewMaterial()) {
303 top_view_inset = 303 top_view_inset =
304 GetWindow()->GetIntProperty(wm::WmWindowProperty::TOP_VIEW_INSET); 304 GetWindow()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET);
305 title_height = close_button_->GetPreferredSize().height(); 305 title_height = close_button_->GetPreferredSize().height();
306 } 306 }
307 gfx::Rect selector_item_bounds = 307 gfx::Rect selector_item_bounds =
308 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio( 308 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio(
309 screen_rect, target_bounds, top_view_inset, title_height); 309 screen_rect, target_bounds, top_view_inset, title_height);
310 gfx::Transform transform = ScopedTransformOverviewWindow::GetTransformForRect( 310 gfx::Transform transform = ScopedTransformOverviewWindow::GetTransformForRect(
311 screen_rect, selector_item_bounds); 311 screen_rect, selector_item_bounds);
312 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; 312 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings;
313 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); 313 transform_window_.BeginScopedAnimation(animation_type, &animation_settings);
314 transform_window_.SetTransform(root_window_, transform); 314 transform_window_.SetTransform(root_window_, transform);
(...skipping 15 matching lines...) Expand all
330 SetupFadeInAfterLayout(window_label_.get()); 330 SetupFadeInAfterLayout(window_label_.get());
331 } 331 }
332 332
333 gfx::Rect label_bounds = root_window_->ConvertRectFromScreen(window_bounds); 333 gfx::Rect label_bounds = root_window_->ConvertRectFromScreen(window_bounds);
334 window_label_button_view_->set_top_padding(label_bounds.height() - 334 window_label_button_view_->set_top_padding(label_bounds.height() -
335 kVerticalLabelPadding); 335 kVerticalLabelPadding);
336 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = 336 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings =
337 ScopedOverviewAnimationSettingsFactory::Get() 337 ScopedOverviewAnimationSettingsFactory::Get()
338 ->CreateOverviewAnimationSettings( 338 ->CreateOverviewAnimationSettings(
339 animation_type, 339 animation_type,
340 wm::WmLookup::Get()->GetWindowForWidget(window_label_.get())); 340 WmLookup::Get()->GetWindowForWidget(window_label_.get()));
341 341
342 window_label_->SetBounds(label_bounds); 342 window_label_->SetBounds(label_bounds);
343 } 343 }
344 344
345 void WindowSelectorItem::CreateWindowLabel(const base::string16& title) { 345 void WindowSelectorItem::CreateWindowLabel(const base::string16& title) {
346 const bool material = ash::MaterialDesignController::IsOverviewMaterial(); 346 const bool material = ash::MaterialDesignController::IsOverviewMaterial();
347 window_label_.reset(new views::Widget); 347 window_label_.reset(new views::Widget);
348 views::Widget::InitParams params; 348 views::Widget::InitParams params;
349 params.type = views::Widget::InitParams::TYPE_POPUP; 349 params.type = views::Widget::InitParams::TYPE_POPUP;
350 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 350 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 OverviewAnimationType animation_type) { 382 OverviewAnimationType animation_type) {
383 gfx::Rect transformed_window_bounds = 383 gfx::Rect transformed_window_bounds =
384 root_window_->ConvertRectFromScreen(GetTransformedBounds( 384 root_window_->ConvertRectFromScreen(GetTransformedBounds(
385 GetWindow(), close_button_->GetPreferredSize().height())); 385 GetWindow(), close_button_->GetPreferredSize().height()));
386 386
387 { 387 {
388 if (!close_button_->visible()) { 388 if (!close_button_->visible()) {
389 close_button_->SetVisible(true); 389 close_button_->SetVisible(true);
390 SetupFadeInAfterLayout(&close_button_widget_); 390 SetupFadeInAfterLayout(&close_button_widget_);
391 } 391 }
392 wm::WmWindow* close_button_widget_window = 392 WmWindow* close_button_widget_window =
393 wm::WmLookup::Get()->GetWindowForWidget(&close_button_widget_); 393 WmLookup::Get()->GetWindowForWidget(&close_button_widget_);
394 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = 394 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings =
395 ScopedOverviewAnimationSettingsFactory::Get() 395 ScopedOverviewAnimationSettingsFactory::Get()
396 ->CreateOverviewAnimationSettings(animation_type, 396 ->CreateOverviewAnimationSettings(animation_type,
397 close_button_widget_window); 397 close_button_widget_window);
398 398
399 gfx::Transform close_button_transform; 399 gfx::Transform close_button_transform;
400 close_button_transform.Translate(transformed_window_bounds.right(), 400 close_button_transform.Translate(transformed_window_bounds.right(),
401 transformed_window_bounds.y()); 401 transformed_window_bounds.y());
402 close_button_widget_window->SetTransform(close_button_transform); 402 close_button_widget_window->SetTransform(close_button_transform);
403 } 403 }
404 404
405 // TODO(varkha): Figure out how to draw |window_label_| opaquely over the 405 // TODO(varkha): Figure out how to draw |window_label_| opaquely over the
406 // occluded header or truly hide the headers in overview mode. 406 // occluded header or truly hide the headers in overview mode.
407 if (ash::MaterialDesignController::IsOverviewMaterial()) { 407 if (ash::MaterialDesignController::IsOverviewMaterial()) {
408 gfx::Rect label_rect(close_button_->GetPreferredSize()); 408 gfx::Rect label_rect(close_button_->GetPreferredSize());
409 label_rect.set_y(-label_rect.height()); 409 label_rect.set_y(-label_rect.height());
410 label_rect.set_width(transformed_window_bounds.width() - 410 label_rect.set_width(transformed_window_bounds.width() -
411 label_rect.width()); 411 label_rect.width());
412 window_label_->SetBounds(label_rect); 412 window_label_->SetBounds(label_rect);
413 413
414 if (!window_label_button_view_->visible()) { 414 if (!window_label_button_view_->visible()) {
415 window_label_button_view_->SetVisible(true); 415 window_label_button_view_->SetVisible(true);
416 SetupFadeInAfterLayout(window_label_.get()); 416 SetupFadeInAfterLayout(window_label_.get());
417 } 417 }
418 wm::WmWindow* window_label_window = 418 WmWindow* window_label_window =
419 wm::WmLookup::Get()->GetWindowForWidget(window_label_.get()); 419 WmLookup::Get()->GetWindowForWidget(window_label_.get());
420 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = 420 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings =
421 ScopedOverviewAnimationSettingsFactory::Get() 421 ScopedOverviewAnimationSettingsFactory::Get()
422 ->CreateOverviewAnimationSettings(animation_type, 422 ->CreateOverviewAnimationSettings(animation_type,
423 window_label_window); 423 window_label_window);
424 gfx::Transform label_transform; 424 gfx::Transform label_transform;
425 label_transform.Translate(transformed_window_bounds.x(), 425 label_transform.Translate(transformed_window_bounds.x(),
426 transformed_window_bounds.y()); 426 transformed_window_bounds.y());
427 window_label_window->SetTransform(label_transform); 427 window_label_window->SetTransform(label_transform);
428 } 428 }
429 } 429 }
430 430
431 void WindowSelectorItem::UpdateCloseButtonAccessibilityName() { 431 void WindowSelectorItem::UpdateCloseButtonAccessibilityName() {
432 close_button_->SetAccessibleName(l10n_util::GetStringFUTF16( 432 close_button_->SetAccessibleName(l10n_util::GetStringFUTF16(
433 IDS_ASH_OVERVIEW_CLOSE_ITEM_BUTTON_ACCESSIBLE_NAME, 433 IDS_ASH_OVERVIEW_CLOSE_ITEM_BUTTON_ACCESSIBLE_NAME,
434 GetWindow()->GetTitle())); 434 GetWindow()->GetTitle()));
435 } 435 }
436 436
437 } // namespace ash 437 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698