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

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

Issue 2633643002: [ash-md] Reduces dimensions of texture layers in overview mode (Closed)
Patch Set: [ash-md] Reduces dimensions of texture layers in overview mode (test) Created 3 years, 11 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_item.h" 5 #include "ash/common/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/material_design/material_design_controller.h" 10 #include "ash/common/material_design/material_design_controller.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 // Label background color once in overview mode. 70 // Label background color once in overview mode.
71 static const SkColor kLabelBackgroundColor = SkColorSetARGB(25, 255, 255, 255); 71 static const SkColor kLabelBackgroundColor = SkColorSetARGB(25, 255, 255, 255);
72 72
73 // Label background color when exiting overview mode. 73 // Label background color when exiting overview mode.
74 static const SkColor kLabelExitColor = SkColorSetARGB(255, 90, 90, 90); 74 static const SkColor kLabelExitColor = SkColorSetARGB(255, 90, 90, 90);
75 75
76 // Corner radius for the selection tiles. 76 // Corner radius for the selection tiles.
77 static int kLabelBackgroundRadius = 2; 77 static int kLabelBackgroundRadius = 2;
78 78
79 // Vertical padding for the label, on top of it.
80 static const int kVerticalLabelPadding = 20;
81
82 // Horizontal padding for the label, on both sides. 79 // Horizontal padding for the label, on both sides.
83 static const int kHorizontalLabelPadding = 8; 80 static const int kHorizontalLabelPadding = 8;
84 81
85 // Height of an item header. 82 // Height of an item header.
86 static const int kHeaderHeight = 32; 83 static const int kHeaderHeight = 32;
87 84
88 // Opacity for dimmed items. 85 // Opacity for dimmed items.
89 static const float kDimmedItemOpacity = 0.5f; 86 static const float kDimmedItemOpacity = 0.5f;
90 87
91 // Opacity for fading out during closing a window. 88 // Opacity for fading out during closing a window.
(...skipping 26 matching lines...) Expand all
118 std::unique_ptr<ScopedOverviewAnimationSettings> 115 std::unique_ptr<ScopedOverviewAnimationSettings>
119 scoped_overview_animation_settings = 116 scoped_overview_animation_settings =
120 ScopedOverviewAnimationSettingsFactory::Get() 117 ScopedOverviewAnimationSettingsFactory::Get()
121 ->CreateOverviewAnimationSettings( 118 ->CreateOverviewAnimationSettings(
122 OverviewAnimationType:: 119 OverviewAnimationType::
123 OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN, 120 OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN,
124 window); 121 window);
125 window->SetOpacity(1.0f); 122 window->SetOpacity(1.0f);
126 } 123 }
127 124
125 // A Button that has a listener and listens to mouse clicks on the visible part
126 // of an overview window.
127 class ShieldButton : public views::CustomButton {
128 public:
129 ShieldButton(views::ButtonListener* listener, const base::string16& name)
130 : views::CustomButton(listener) {
131 SetAccessibleName(name);
132 }
133 ~ShieldButton() override {}
134
135 // When WindowSelectorItem (which is a ButtonListener) is destroyed, its
136 // |item_widget_| is allowed to stay around to complete any animations.
137 // Resetting the listener in all views that are targeted by events is
138 // necessary to prevent a crash when a user clicks on the fading out widget
139 // after the WindowSelectorItem has been destroyed.
140 void ResetListener() { listener_ = nullptr; }
141
142 protected:
143 // views::View:
144 const char* GetClassName() const override { return "ShieldButton"; }
145
146 private:
147 DISALLOW_COPY_AND_ASSIGN(ShieldButton);
148 };
149
128 } // namespace 150 } // namespace
129 151
130 WindowSelectorItem::OverviewCloseButton::OverviewCloseButton( 152 WindowSelectorItem::OverviewCloseButton::OverviewCloseButton(
131 views::ButtonListener* listener) 153 views::ButtonListener* listener)
132 : views::ImageButton(listener) { 154 : views::ImageButton(listener) {
133 SetImage(views::CustomButton::STATE_NORMAL, 155 SetImage(views::CustomButton::STATE_NORMAL,
134 gfx::CreateVectorIcon(kWindowControlCloseIcon, kCloseButtonColor)); 156 gfx::CreateVectorIcon(kWindowControlCloseIcon, kCloseButtonColor));
135 SetImageAlignment(views::ImageButton::ALIGN_CENTER, 157 SetImageAlignment(views::ImageButton::ALIGN_CENTER,
136 views::ImageButton::ALIGN_MIDDLE); 158 views::ImageButton::ALIGN_MIDDLE);
137 SetMinimumImageSize(gfx::Size(kHeaderHeight, kHeaderHeight)); 159 SetMinimumImageSize(gfx::Size(kHeaderHeight, kHeaderHeight));
(...skipping 24 matching lines...) Expand all
162 WmWindow* item_window, 184 WmWindow* item_window,
163 int corner_radius, 185 int corner_radius,
164 SkColor background) 186 SkColor background)
165 : item_(item), 187 : item_(item),
166 item_window_(item_window), 188 item_window_(item_window),
167 corner_radius_(corner_radius), 189 corner_radius_(corner_radius),
168 initial_color_(background), 190 initial_color_(background),
169 target_color_(background), 191 target_color_(background),
170 current_value_(0), 192 current_value_(0),
171 layer_(nullptr), 193 layer_(nullptr),
172 animation_(new gfx::SlideAnimation(this)) {} 194 animation_(new gfx::SlideAnimation(this)) {
195 SetPaintToLayer(true);
196 layer()->SetFillsBoundsOpaquely(false);
197 }
173 198
174 ~RoundedContainerView() override { StopObservingLayerAnimations(); } 199 ~RoundedContainerView() override { StopObservingLayerAnimations(); }
175 200
176 void OnItemRestored() { 201 void OnItemRestored() {
177 item_ = nullptr; 202 item_ = nullptr;
178 item_window_ = nullptr; 203 item_window_ = nullptr;
179 } 204 }
180 205
181 // Starts observing layer animations so that actions can be taken when 206 // Starts observing layer animations so that actions can be taken when
182 // particular animations (opacity) complete. It should only be called once 207 // particular animations (opacity) complete. It should only be called once
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 canvas->ClipPath(path, true); 272 canvas->ClipPath(path, true);
248 273
249 SkColor target_color = initial_color_; 274 SkColor target_color = initial_color_;
250 if (target_color_ != target_color) { 275 if (target_color_ != target_color) {
251 target_color = color_utils::AlphaBlend(target_color_, initial_color_, 276 target_color = color_utils::AlphaBlend(target_color_, initial_color_,
252 current_value_); 277 current_value_);
253 } 278 }
254 canvas->DrawColor(target_color); 279 canvas->DrawColor(target_color);
255 } 280 }
256 281
282 const char* GetClassName() const override { return "RoundedContainerView"; }
283
257 private: 284 private:
258 // gfx::AnimationDelegate: 285 // gfx::AnimationDelegate:
259 void AnimationEnded(const gfx::Animation* animation) override { 286 void AnimationEnded(const gfx::Animation* animation) override {
260 initial_color_ = target_color_; 287 initial_color_ = target_color_;
261 // Tabbed browser windows show the overview mode header behind the window 288 // Tabbed browser windows show the overview mode header behind the window
262 // during the initial animation. Once the initial fade-in completes and the 289 // during the initial animation. Once the initial fade-in completes and the
263 // overview header is fully exposed update stacking to keep the label above 290 // overview header is fully exposed update stacking to keep the label above
264 // the item which prevents input events from reaching the window. 291 // the item which prevents input events from reaching the window.
265 WmWindow* label_window = WmLookup::Get()->GetWindowForWidget(GetWidget()); 292 WmWindow* widget_window = WmLookup::Get()->GetWindowForWidget(GetWidget());
266 if (label_window && item_window_) 293 if (widget_window && item_window_)
267 label_window->GetParent()->StackChildAbove(label_window, item_window_); 294 widget_window->GetParent()->StackChildAbove(widget_window, item_window_);
268 item_window_ = nullptr; 295 item_window_ = nullptr;
269 } 296 }
270 297
271 void AnimationProgressed(const gfx::Animation* animation) override { 298 void AnimationProgressed(const gfx::Animation* animation) override {
272 current_value_ = animation_->CurrentValueBetween(0, 255); 299 current_value_ = animation_->CurrentValueBetween(0, 255);
273 SchedulePaint(); 300 SchedulePaint();
274 } 301 }
275 302
276 void AnimationCanceled(const gfx::Animation* animation) override { 303 void AnimationCanceled(const gfx::Animation* animation) override {
277 item_window_ = nullptr; 304 item_window_ = nullptr;
(...skipping 28 matching lines...) Expand all
306 int corner_radius_; 333 int corner_radius_;
307 SkColor initial_color_; 334 SkColor initial_color_;
308 SkColor target_color_; 335 SkColor target_color_;
309 int current_value_; 336 int current_value_;
310 ui::Layer* layer_; 337 ui::Layer* layer_;
311 std::unique_ptr<gfx::SlideAnimation> animation_; 338 std::unique_ptr<gfx::SlideAnimation> animation_;
312 339
313 DISALLOW_COPY_AND_ASSIGN(RoundedContainerView); 340 DISALLOW_COPY_AND_ASSIGN(RoundedContainerView);
314 }; 341 };
315 342
316 WindowSelectorItem::OverviewLabelButton::OverviewLabelButton( 343 // A Container View that has a ShieldButton to listen to events. The
317 views::ButtonListener* listener, 344 // ShieldButton covers most of the View except for the transparent gap between
318 const base::string16& text) 345 // the windows and is visually transparent. The ShieldButton owns a background
319 : LabelButton(listener, text) {} 346 // non-transparent view positioned at the ShieldButton top. The background view
320 347 // in its turn owns an item text label and a close button.
321 WindowSelectorItem::OverviewLabelButton::~OverviewLabelButton() {} 348 // The text label does not receive events, however the close button is higher in
322 349 // Z-order than its parent and receives events forwarding them to the same
323 void WindowSelectorItem::OverviewLabelButton::SetBackgroundColorHint( 350 // |listener| (i.e. WindowSelectorItem::ButtonPressed()).
324 SkColor color) {
325 // Tell the label what color it will be drawn onto. It will use whether the
326 // background color is opaque or transparent to decide whether to use subpixel
327 // rendering. Does not actually set the label's background color.
328 label()->SetBackgroundColor(color);
329 }
330
331 gfx::Rect WindowSelectorItem::OverviewLabelButton::GetChildAreaBounds() {
332 gfx::Rect bounds = GetLocalBounds();
333 bounds.Inset(padding_ + gfx::Insets(0, kHorizontalLabelPadding));
334 return bounds;
335 }
336
337 // Container View that has an item label and a close button as children.
338 class WindowSelectorItem::CaptionContainerView : public views::View { 351 class WindowSelectorItem::CaptionContainerView : public views::View {
339 public: 352 public:
340 CaptionContainerView(WindowSelectorItem::OverviewLabelButton* label, 353 CaptionContainerView(ButtonListener* listener,
354 views::Label* label,
341 views::ImageButton* close_button, 355 views::ImageButton* close_button,
342 WindowSelectorItem::RoundedContainerView* background) 356 WindowSelectorItem::RoundedContainerView* background)
343 : label_(label), close_button_(close_button), background_(background) { 357 : listener_button_(new ShieldButton(listener, label->text())),
344 AddChildView(background_); 358 background_(background),
345 AddChildView(label_); 359 label_(label),
346 AddChildView(close_button_); 360 close_button_(close_button) {
361 background_->AddChildView(label_);
362 background_->AddChildView(close_button_);
363 listener_button_->AddChildView(background_);
364 AddChildView(listener_button_);
347 } 365 }
348 366
367 ShieldButton* listener_button() { return listener_button_; }
368
349 protected: 369 protected:
350 // views::View: 370 // views::View:
351 void Layout() override { 371 void Layout() override {
352 // Position close button in the top right corner sized to its icon size and 372 // Position close button in the top right corner sized to its icon size and
353 // the label in the top left corner as tall as the button and extending to 373 // the label in the top left corner as tall as the button and extending to
354 // the button's left edge. 374 // the button's left edge.
355 // The rest of this container view serves as a shield to prevent input 375 // The rest of this container view serves as a shield to prevent input
356 // events from reaching the transformed window in overview. 376 // events from reaching the transformed window in overview.
357 gfx::Rect bounds(GetLocalBounds()); 377 gfx::Rect bounds(GetLocalBounds());
358 bounds.Inset(kWindowSelectorMargin, kWindowSelectorMargin); 378 bounds.Inset(kWindowSelectorMargin, kWindowSelectorMargin);
359 gfx::Rect background_bounds(bounds); 379 listener_button_->SetBoundsRect(bounds);
360 background_bounds.set_height(close_button_->GetPreferredSize().height()); 380
381 const int visible_height = close_button_->GetPreferredSize().height();
382 gfx::Rect background_bounds(gfx::Rect(bounds.size()));
383 background_bounds.set_height(visible_height);
361 background_->SetBoundsRect(background_bounds); 384 background_->SetBoundsRect(background_bounds);
362 385
363 const int visible_height = close_button_->GetPreferredSize().height(); 386 bounds = background_bounds;
364 gfx::Insets label_padding(0, 0, bounds.height() - visible_height, 387 bounds.Inset(kHorizontalLabelPadding, 0,
365 visible_height); 388 kHorizontalLabelPadding + visible_height, 0);
366 label_->set_padding(label_padding);
367 label_->SetBoundsRect(bounds); 389 label_->SetBoundsRect(bounds);
368 bounds.set_x(bounds.right() - visible_height); 390
391 bounds = background_bounds;
392 bounds.set_x(bounds.width() - visible_height);
369 bounds.set_width(visible_height); 393 bounds.set_width(visible_height);
370 bounds.set_height(visible_height);
371 close_button_->SetBoundsRect(bounds); 394 close_button_->SetBoundsRect(bounds);
372 } 395 }
373 396
397 const char* GetClassName() const override { return "CaptionContainerView"; }
398
374 private: 399 private:
375 WindowSelectorItem::OverviewLabelButton* label_; 400 ShieldButton* listener_button_;
401 WindowSelectorItem::RoundedContainerView* background_;
402 views::Label* label_;
376 views::ImageButton* close_button_; 403 views::ImageButton* close_button_;
377 WindowSelectorItem::RoundedContainerView* background_;
378 404
379 DISALLOW_COPY_AND_ASSIGN(CaptionContainerView); 405 DISALLOW_COPY_AND_ASSIGN(CaptionContainerView);
380 }; 406 };
381 407
382 WindowSelectorItem::WindowSelectorItem(WmWindow* window, 408 WindowSelectorItem::WindowSelectorItem(WmWindow* window,
383 WindowSelector* window_selector) 409 WindowSelector* window_selector)
384 : dimmed_(false), 410 : dimmed_(false),
385 root_window_(window->GetRootWindow()), 411 root_window_(window->GetRootWindow()),
386 transform_window_(window), 412 transform_window_(window),
387 in_bounds_update_(false), 413 in_bounds_update_(false),
388 selected_(false), 414 selected_(false),
389 caption_container_view_(nullptr), 415 caption_container_view_(nullptr),
390 window_label_button_view_(nullptr), 416 label_view_(nullptr),
391 close_button_(new OverviewCloseButton(this)), 417 close_button_(new OverviewCloseButton(this)),
392 window_selector_(window_selector), 418 window_selector_(window_selector),
393 background_view_(nullptr) { 419 background_view_(nullptr) {
394 CreateWindowLabel(window->GetTitle()); 420 CreateWindowLabel(window->GetTitle());
395 GetWindow()->AddObserver(this); 421 GetWindow()->AddObserver(this);
396 } 422 }
397 423
398 WindowSelectorItem::~WindowSelectorItem() { 424 WindowSelectorItem::~WindowSelectorItem() {
399 GetWindow()->RemoveObserver(this); 425 GetWindow()->RemoveObserver(this);
400 } 426 }
401 427
402 WmWindow* WindowSelectorItem::GetWindow() { 428 WmWindow* WindowSelectorItem::GetWindow() {
403 return transform_window_.window(); 429 return transform_window_.window();
404 } 430 }
405 431
406 void WindowSelectorItem::RestoreWindow() { 432 void WindowSelectorItem::RestoreWindow() {
407 window_label_button_view_->ResetListener(); 433 caption_container_view_->listener_button()->ResetListener();
408 close_button_->ResetListener(); 434 close_button_->ResetListener();
409 transform_window_.RestoreWindow(); 435 transform_window_.RestoreWindow();
410 if (background_view_) { 436 if (background_view_) {
411 background_view_->OnItemRestored(); 437 background_view_->OnItemRestored();
412 background_view_ = nullptr; 438 background_view_ = nullptr;
413 } 439 }
414 UpdateHeaderLayout( 440 UpdateHeaderLayout(
415 HeaderFadeInMode::EXIT, 441 HeaderFadeInMode::EXIT,
416 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS); 442 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS);
417 } 443 }
418 444
419 void WindowSelectorItem::Shutdown() { 445 void WindowSelectorItem::Shutdown() {
420 if (transform_window_.GetTopInset()) { 446 if (transform_window_.GetTopInset()) {
421 // Activating a window (even when it is the window that was active before 447 // Activating a window (even when it is the window that was active before
422 // overview) results in stacking it at the top. Maintain the label window 448 // overview) results in stacking it at the top. Maintain the label window
423 // stacking position above the item to make the header transformation more 449 // stacking position above the item to make the header transformation more
424 // gradual upon exiting the overview mode. 450 // gradual upon exiting the overview mode.
425 WmWindow* label_window = 451 WmWindow* widget_window =
426 WmLookup::Get()->GetWindowForWidget(window_label_.get()); 452 WmLookup::Get()->GetWindowForWidget(item_widget_.get());
427 453
428 // |label_window| was originally created in the same container as the 454 // |widget_window| was originally created in the same container as the
429 // |transform_window_| but when closing overview the |transform_window_| 455 // |transform_window_| but when closing overview the |transform_window_|
430 // could have been reparented if a drag was active. Only change stacking 456 // could have been reparented if a drag was active. Only change stacking
431 // if the windows still belong to the same container. 457 // if the windows still belong to the same container.
432 if (label_window->GetParent() == transform_window_.window()->GetParent()) { 458 if (widget_window->GetParent() == transform_window_.window()->GetParent()) {
433 label_window->GetParent()->StackChildAbove(label_window, 459 widget_window->GetParent()->StackChildAbove(widget_window,
434 transform_window_.window()); 460 transform_window_.window());
435 } 461 }
436 } 462 }
437 if (background_view_) { 463 if (background_view_) {
438 background_view_->OnItemRestored(); 464 background_view_->OnItemRestored();
439 background_view_ = nullptr; 465 background_view_ = nullptr;
440 } 466 }
441 FadeOut(std::move(window_label_)); 467 FadeOut(std::move(item_widget_));
442 } 468 }
443 469
444 void WindowSelectorItem::PrepareForOverview() { 470 void WindowSelectorItem::PrepareForOverview() {
445 transform_window_.PrepareForOverview(); 471 transform_window_.PrepareForOverview();
446 UpdateHeaderLayout(HeaderFadeInMode::ENTER, 472 UpdateHeaderLayout(HeaderFadeInMode::ENTER,
447 OverviewAnimationType::OVERVIEW_ANIMATION_NONE); 473 OverviewAnimationType::OVERVIEW_ANIMATION_NONE);
448 } 474 }
449 475
450 bool WindowSelectorItem::Contains(const WmWindow* target) const { 476 bool WindowSelectorItem::Contains(const WmWindow* target) const {
451 return transform_window_.Contains(target); 477 return transform_window_.Contains(target);
(...skipping 27 matching lines...) Expand all
479 animation_settings_shadow.SetTweenType( 505 animation_settings_shadow.SetTweenType(
480 selected ? gfx::Tween::FAST_OUT_LINEAR_IN 506 selected ? gfx::Tween::FAST_OUT_LINEAR_IN
481 : gfx::Tween::LINEAR_OUT_SLOW_IN); 507 : gfx::Tween::LINEAR_OUT_SLOW_IN);
482 animation_settings_shadow.SetPreemptionStrategy( 508 animation_settings_shadow.SetPreemptionStrategy(
483 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 509 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
484 shadow_->shadow_layer()->SetOpacity(selected ? 0.0f : 1.0f); 510 shadow_->shadow_layer()->SetOpacity(selected ? 0.0f : 1.0f);
485 } 511 }
486 } 512 }
487 513
488 void WindowSelectorItem::SendAccessibleSelectionEvent() { 514 void WindowSelectorItem::SendAccessibleSelectionEvent() {
489 window_label_button_view_->NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, 515 caption_container_view_->listener_button()->NotifyAccessibilityEvent(
490 true); 516 ui::AX_EVENT_SELECTION, true);
491 } 517 }
492 518
493 void WindowSelectorItem::CloseWindow() { 519 void WindowSelectorItem::CloseWindow() {
494 gfx::Rect inset_bounds(target_bounds_); 520 gfx::Rect inset_bounds(target_bounds_);
495 inset_bounds.Inset(target_bounds_.width() * kPreCloseScale, 521 inset_bounds.Inset(target_bounds_.width() * kPreCloseScale,
496 target_bounds_.height() * kPreCloseScale); 522 target_bounds_.height() * kPreCloseScale);
497 OverviewAnimationType animation_type = 523 OverviewAnimationType animation_type =
498 OverviewAnimationType::OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM; 524 OverviewAnimationType::OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM;
499 // Scale down both the window and label. 525 // Scale down both the window and label.
500 SetBounds(inset_bounds, animation_type); 526 SetBounds(inset_bounds, animation_type);
(...skipping 20 matching lines...) Expand all
521 SetOpacity(dimmed ? kDimmedItemOpacity : 1.0f); 547 SetOpacity(dimmed ? kDimmedItemOpacity : 1.0f);
522 } 548 }
523 549
524 void WindowSelectorItem::ButtonPressed(views::Button* sender, 550 void WindowSelectorItem::ButtonPressed(views::Button* sender,
525 const ui::Event& event) { 551 const ui::Event& event) {
526 if (sender == close_button_) { 552 if (sender == close_button_) {
527 WmShell::Get()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW_CLOSE_BUTTON); 553 WmShell::Get()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW_CLOSE_BUTTON);
528 CloseWindow(); 554 CloseWindow();
529 return; 555 return;
530 } 556 }
531 CHECK(sender == window_label_button_view_); 557 CHECK(sender == caption_container_view_->listener_button());
532 window_selector_->SelectWindow(transform_window_.window()); 558 window_selector_->SelectWindow(transform_window_.window());
533 } 559 }
534 560
535 void WindowSelectorItem::OnWindowDestroying(WmWindow* window) { 561 void WindowSelectorItem::OnWindowDestroying(WmWindow* window) {
536 window->RemoveObserver(this); 562 window->RemoveObserver(this);
537 transform_window_.OnWindowDestroyed(); 563 transform_window_.OnWindowDestroyed();
538 } 564 }
539 565
540 void WindowSelectorItem::OnWindowTitleChanged(WmWindow* window) { 566 void WindowSelectorItem::OnWindowTitleChanged(WmWindow* window) {
541 // TODO(flackr): Maybe add the new title to a vector of titles so that we can 567 // TODO(flackr): Maybe add the new title to a vector of titles so that we can
542 // filter any of the titles the window had while in the overview session. 568 // filter any of the titles the window had while in the overview session.
543 window_label_button_view_->SetText(window->GetTitle()); 569 label_view_->SetText(window->GetTitle());
544 UpdateCloseButtonAccessibilityName(); 570 UpdateAccessibilityName();
545 } 571 }
546 572
547 float WindowSelectorItem::GetItemScale(const gfx::Size& size) { 573 float WindowSelectorItem::GetItemScale(const gfx::Size& size) {
548 gfx::Size inset_size(size.width(), size.height() - 2 * kWindowMargin); 574 gfx::Size inset_size(size.width(), size.height() - 2 * kWindowMargin);
549 return ScopedTransformOverviewWindow::GetItemScale( 575 return ScopedTransformOverviewWindow::GetItemScale(
550 transform_window_.GetTargetBoundsInScreen().size(), inset_size, 576 transform_window_.GetTargetBoundsInScreen().size(), inset_size,
551 transform_window_.GetTopInset(), 577 transform_window_.GetTopInset(),
552 close_button_->GetPreferredSize().height()); 578 close_button_->GetPreferredSize().height());
553 } 579 }
554 580
(...skipping 17 matching lines...) Expand all
572 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio( 598 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio(
573 screen_rect, target_bounds, top_view_inset, title_height); 599 screen_rect, target_bounds, top_view_inset, title_height);
574 gfx::Transform transform = ScopedTransformOverviewWindow::GetTransformForRect( 600 gfx::Transform transform = ScopedTransformOverviewWindow::GetTransformForRect(
575 screen_rect, selector_item_bounds); 601 screen_rect, selector_item_bounds);
576 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; 602 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings;
577 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); 603 transform_window_.BeginScopedAnimation(animation_type, &animation_settings);
578 transform_window_.SetTransform(root_window_, transform); 604 transform_window_.SetTransform(root_window_, transform);
579 } 605 }
580 606
581 void WindowSelectorItem::SetOpacity(float opacity) { 607 void WindowSelectorItem::SetOpacity(float opacity) {
582 window_label_->SetOpacity(opacity); 608 item_widget_->SetOpacity(opacity);
583 if (background_view_) { 609 if (background_view_) {
584 background_view_->AnimateBackgroundOpacity( 610 background_view_->AnimateBackgroundOpacity(
585 selected_ ? 0.f : kHeaderOpacity * opacity); 611 selected_ ? 0.f : kHeaderOpacity * opacity);
586 } 612 }
587 transform_window_.SetOpacity(opacity); 613 transform_window_.SetOpacity(opacity);
588 } 614 }
589 615
590 void WindowSelectorItem::UpdateWindowLabel(
591 const gfx::Rect& window_bounds,
592 OverviewAnimationType animation_type) {
593 if (!window_label_->IsVisible()) {
594 window_label_->Show();
595 SetupFadeInAfterLayout(window_label_.get());
596 }
597
598 gfx::Rect label_bounds = root_window_->ConvertRectFromScreen(window_bounds);
599 window_label_button_view_->set_padding(
600 gfx::Insets(label_bounds.height() - kVerticalLabelPadding, 0, 0, 0));
601 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings =
602 ScopedOverviewAnimationSettingsFactory::Get()
603 ->CreateOverviewAnimationSettings(
604 animation_type,
605 WmLookup::Get()->GetWindowForWidget(window_label_.get()));
606
607 WmWindow* window_label_window =
608 WmLookup::Get()->GetWindowForWidget(window_label_.get());
609 window_label_window->SetBounds(label_bounds);
610 }
611
612 void WindowSelectorItem::CreateWindowLabel(const base::string16& title) { 616 void WindowSelectorItem::CreateWindowLabel(const base::string16& title) {
613 background_view_ = new RoundedContainerView(this, transform_window_.window(), 617 background_view_ = new RoundedContainerView(this, transform_window_.window(),
614 kLabelBackgroundRadius, 618 kLabelBackgroundRadius,
615 transform_window_.GetTopColor()); 619 transform_window_.GetTopColor());
616 // |background_view_| will get added as a child to CaptionContainerView. 620 // |background_view_| will get added as a child to CaptionContainerView.
617 views::Widget::InitParams params_label; 621 views::Widget::InitParams params_label;
618 params_label.type = views::Widget::InitParams::TYPE_POPUP; 622 params_label.type = views::Widget::InitParams::TYPE_POPUP;
619 params_label.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 623 params_label.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
620 params_label.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 624 params_label.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
621 params_label.visible_on_all_workspaces = true; 625 params_label.visible_on_all_workspaces = true;
626 params_label.layer_type = ui::LAYER_NOT_DRAWN;
622 params_label.name = "OverviewModeLabel"; 627 params_label.name = "OverviewModeLabel";
623 params_label.activatable = 628 params_label.activatable =
624 views::Widget::InitParams::Activatable::ACTIVATABLE_DEFAULT; 629 views::Widget::InitParams::Activatable::ACTIVATABLE_DEFAULT;
625 params_label.accept_events = true; 630 params_label.accept_events = true;
626 window_label_.reset(new views::Widget); 631 item_widget_.reset(new views::Widget);
627 root_window_->GetRootWindowController() 632 root_window_->GetRootWindowController()
628 ->ConfigureWidgetInitParamsForContainer( 633 ->ConfigureWidgetInitParamsForContainer(
629 window_label_.get(), 634 item_widget_.get(),
630 transform_window_.window()->GetParent()->GetShellWindowId(), 635 transform_window_.window()->GetParent()->GetShellWindowId(),
631 &params_label); 636 &params_label);
632 window_label_->set_focus_on_creation(false); 637 item_widget_->set_focus_on_creation(false);
633 window_label_->Init(params_label); 638 item_widget_->Init(params_label);
634 window_label_button_view_ = new OverviewLabelButton(this, title); 639 WmWindow* widget_window =
635 window_label_button_view_->SetBorder(views::NullBorder()); 640 WmLookup::Get()->GetWindowForWidget(item_widget_.get());
636 window_label_button_view_->SetEnabledTextColors(kLabelColor);
637 window_label_button_view_->set_animate_on_state_change(false);
638 WmWindow* label_window =
639 WmLookup::Get()->GetWindowForWidget(window_label_.get());
640 if (transform_window_.GetTopInset()) { 641 if (transform_window_.GetTopInset()) {
641 // For windows with headers the overview header fades in above the 642 // For windows with headers the overview header fades in above the
642 // original window header. 643 // original window header.
643 label_window->GetParent()->StackChildAbove(label_window, 644 widget_window->GetParent()->StackChildAbove(widget_window,
644 transform_window_.window()); 645 transform_window_.window());
645 } else { 646 } else {
646 // For tabbed windows the overview header slides from behind. The stacking 647 // For tabbed windows the overview header slides from behind. The stacking
647 // is then corrected when the animation completes. 648 // is then corrected when the animation completes.
648 label_window->GetParent()->StackChildBelow(label_window, 649 widget_window->GetParent()->StackChildBelow(widget_window,
649 transform_window_.window()); 650 transform_window_.window());
650 } 651 }
651 window_label_button_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 652 label_view_ = new views::Label(title);
652 // Hint at the background color that the label will be drawn onto (for 653 label_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
653 // subpixel antialiasing). Does not actually set the background color. 654 label_view_->SetAutoColorReadabilityEnabled(false);
654 window_label_button_view_->SetBackgroundColorHint(kLabelBackgroundColor); 655 label_view_->SetEnabledColor(kLabelColor);
656 // Tell the label what color it will be drawn onto. It will use whether the
657 // background color is opaque or transparent to decide whether to use
658 // subpixel rendering. Does not actually set the label's background color.
659 label_view_->SetBackgroundColor(kLabelBackgroundColor);
660
655 caption_container_view_ = new CaptionContainerView( 661 caption_container_view_ = new CaptionContainerView(
656 window_label_button_view_, close_button_, background_view_); 662 this, label_view_, close_button_, background_view_);
657 window_label_->SetContentsView(caption_container_view_); 663 item_widget_->SetContentsView(caption_container_view_);
658 window_label_button_view_->SetVisible(false); 664 label_view_->SetVisible(false);
659 window_label_->SetOpacity(0); 665 item_widget_->SetOpacity(0);
660 window_label_->Show(); 666 item_widget_->Show();
661 667
662 // TODO(varkha): Restore shadows when programmatic shadows exist. 668 // TODO(varkha): Restore shadows when programmatic shadows exist.
663 // Note: current shadow implementation does not allow proper animation when 669 // Note: current shadow implementation does not allow proper animation when
664 // the parent layer bounds change during the animation since 670 // the parent layer bounds change during the animation since
665 // Shadow::UpdateLayerBounds() only happens before the animation starts. 671 // Shadow::UpdateLayerBounds() only happens before the animation starts.
666 if (ash::MaterialDesignController::GetMode() == 672 if (ash::MaterialDesignController::GetMode() ==
667 ash::MaterialDesignController::Mode::MATERIAL_EXPERIMENTAL) { 673 ash::MaterialDesignController::Mode::MATERIAL_EXPERIMENTAL) {
668 shadow_.reset(new ::wm::Shadow()); 674 shadow_.reset(new ::wm::Shadow());
669 shadow_->Init(::wm::ShadowElevation::MEDIUM); 675 shadow_->Init(::wm::ShadowElevation::MEDIUM);
670 shadow_->layer()->SetVisible(true); 676 shadow_->layer()->SetVisible(true);
671 window_label_->GetLayer()->Add(shadow_->layer()); 677 item_widget_->GetLayer()->Add(shadow_->layer());
672 } 678 }
673 window_label_->GetLayer()->SetMasksToBounds(false); 679 item_widget_->GetLayer()->SetMasksToBounds(false);
674 } 680 }
675 681
676 void WindowSelectorItem::UpdateHeaderLayout( 682 void WindowSelectorItem::UpdateHeaderLayout(
677 HeaderFadeInMode mode, 683 HeaderFadeInMode mode,
678 OverviewAnimationType animation_type) { 684 OverviewAnimationType animation_type) {
679 gfx::Rect transformed_window_bounds = root_window_->ConvertRectFromScreen( 685 gfx::Rect transformed_window_bounds = root_window_->ConvertRectFromScreen(
680 transform_window_.GetTransformedBounds()); 686 transform_window_.GetTransformedBounds());
681 687
682 gfx::Rect label_rect(close_button_->GetPreferredSize()); 688 gfx::Rect label_rect(close_button_->GetPreferredSize());
683 label_rect.set_width(transformed_window_bounds.width()); 689 label_rect.set_width(transformed_window_bounds.width());
684 // For tabbed windows the initial bounds of the caption are set such that it 690 // For tabbed windows the initial bounds of the caption are set such that it
685 // appears to be "growing" up from the window content area. 691 // appears to be "growing" up from the window content area.
686 label_rect.set_y( 692 label_rect.set_y(
687 (mode != HeaderFadeInMode::ENTER || transform_window_.GetTopInset()) 693 (mode != HeaderFadeInMode::ENTER || transform_window_.GetTopInset())
688 ? -label_rect.height() 694 ? -label_rect.height()
689 : 0); 695 : 0);
690 if (background_view_) { 696 if (background_view_) {
691 if (mode == HeaderFadeInMode::ENTER) { 697 if (mode == HeaderFadeInMode::ENTER) {
692 background_view_->ObserveLayerAnimations(window_label_->GetLayer()); 698 background_view_->ObserveLayerAnimations(item_widget_->GetLayer());
693 background_view_->set_color(kLabelBackgroundColor); 699 background_view_->set_color(kLabelBackgroundColor);
694 // The color will be animated only once the label widget is faded in. 700 // The color will be animated only once the label widget is faded in.
695 } else if (mode == HeaderFadeInMode::EXIT) { 701 } else if (mode == HeaderFadeInMode::EXIT) {
696 // Normally the observer is disconnected when the fade-in animations 702 // Normally the observer is disconnected when the fade-in animations
697 // complete but some tests invoke animations with |NON_ZERO_DURATION| 703 // complete but some tests invoke animations with |NON_ZERO_DURATION|
698 // without waiting for completion so do it here. 704 // without waiting for completion so do it here.
699 background_view_->StopObservingLayerAnimations(); 705 background_view_->StopObservingLayerAnimations();
700 // Make the header visible above the window. It will be faded out when 706 // Make the header visible above the window. It will be faded out when
701 // the Shutdown() is called. 707 // the Shutdown() is called.
702 background_view_->AnimateColor(gfx::Tween::EASE_OUT, 708 background_view_->AnimateColor(gfx::Tween::EASE_OUT,
703 kExitFadeInMilliseconds); 709 kExitFadeInMilliseconds);
704 background_view_->set_color(kLabelExitColor); 710 background_view_->set_color(kLabelExitColor);
705 } 711 }
706 } 712 }
707 if (!window_label_button_view_->visible()) { 713 if (!label_view_->visible()) {
708 window_label_button_view_->SetVisible(true); 714 label_view_->SetVisible(true);
709 SetupFadeInAfterLayout(window_label_.get()); 715 SetupFadeInAfterLayout(item_widget_.get());
710 } 716 }
711 WmWindow* window_label_window = 717 WmWindow* widget_window =
712 WmLookup::Get()->GetWindowForWidget(window_label_.get()); 718 WmLookup::Get()->GetWindowForWidget(item_widget_.get());
713 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = 719 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings =
714 ScopedOverviewAnimationSettingsFactory::Get() 720 ScopedOverviewAnimationSettingsFactory::Get()
715 ->CreateOverviewAnimationSettings(animation_type, 721 ->CreateOverviewAnimationSettings(animation_type, widget_window);
716 window_label_window); 722 // |widget_window| covers both the transformed window and the header
717 // |window_label_window| covers both the transformed window and the header
718 // as well as the gap between the windows to prevent events from reaching 723 // as well as the gap between the windows to prevent events from reaching
719 // the window including its sizing borders. 724 // the window including its sizing borders.
720 if (mode != HeaderFadeInMode::ENTER) { 725 if (mode != HeaderFadeInMode::ENTER) {
721 label_rect.set_height(close_button_->GetPreferredSize().height() + 726 label_rect.set_height(close_button_->GetPreferredSize().height() +
722 transformed_window_bounds.height()); 727 transformed_window_bounds.height());
723 } 728 }
724 label_rect.Inset(-kWindowSelectorMargin, -kWindowSelectorMargin); 729 label_rect.Inset(-kWindowSelectorMargin, -kWindowSelectorMargin);
725 window_label_window->SetBounds(label_rect); 730 widget_window->SetBounds(label_rect);
726 gfx::Transform label_transform; 731 gfx::Transform label_transform;
727 label_transform.Translate(transformed_window_bounds.x(), 732 label_transform.Translate(transformed_window_bounds.x(),
728 transformed_window_bounds.y()); 733 transformed_window_bounds.y());
729 window_label_window->SetTransform(label_transform); 734 widget_window->SetTransform(label_transform);
730 735
731 gfx::Rect shadow_bounds(label_rect.size()); 736 gfx::Rect shadow_bounds(label_rect.size());
732 shadow_bounds.Inset(kWindowSelectorMargin, kWindowSelectorMargin); 737 shadow_bounds.Inset(kWindowSelectorMargin, kWindowSelectorMargin);
733 if (shadow_) 738 if (shadow_)
734 shadow_->SetContentBounds(shadow_bounds); 739 shadow_->SetContentBounds(shadow_bounds);
735 } 740 }
736 741
737 void WindowSelectorItem::AnimateOpacity(float opacity, 742 void WindowSelectorItem::AnimateOpacity(float opacity,
738 OverviewAnimationType animation_type) { 743 OverviewAnimationType animation_type) {
739 DCHECK_GE(opacity, 0.f); 744 DCHECK_GE(opacity, 0.f);
740 DCHECK_LE(opacity, 1.f); 745 DCHECK_LE(opacity, 1.f);
741 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; 746 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings;
742 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); 747 transform_window_.BeginScopedAnimation(animation_type, &animation_settings);
743 transform_window_.SetOpacity(opacity); 748 transform_window_.SetOpacity(opacity);
744 749
745 const float header_opacity = selected_ ? 0.f : kHeaderOpacity * opacity; 750 const float header_opacity = selected_ ? 0.f : kHeaderOpacity * opacity;
746 WmWindow* window_label_window = 751 WmWindow* widget_window =
747 WmLookup::Get()->GetWindowForWidget(window_label_.get()); 752 WmLookup::Get()->GetWindowForWidget(item_widget_.get());
748 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings_label = 753 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings_label =
749 ScopedOverviewAnimationSettingsFactory::Get() 754 ScopedOverviewAnimationSettingsFactory::Get()
750 ->CreateOverviewAnimationSettings(animation_type, 755 ->CreateOverviewAnimationSettings(animation_type, widget_window);
751 window_label_window); 756 widget_window->SetOpacity(header_opacity);
752 window_label_window->SetOpacity(header_opacity);
753 } 757 }
754 758
755 void WindowSelectorItem::UpdateCloseButtonAccessibilityName() { 759 void WindowSelectorItem::UpdateAccessibilityName() {
756 close_button_->SetAccessibleName(l10n_util::GetStringFUTF16( 760 caption_container_view_->listener_button()->SetAccessibleName(
757 IDS_ASH_OVERVIEW_CLOSE_ITEM_BUTTON_ACCESSIBLE_NAME, 761 GetWindow()->GetTitle());
758 GetWindow()->GetTitle()));
759 } 762 }
760 763
761 void WindowSelectorItem::FadeOut(std::unique_ptr<views::Widget> widget) { 764 void WindowSelectorItem::FadeOut(std::unique_ptr<views::Widget> widget) {
762 widget->SetOpacity(1.f); 765 widget->SetOpacity(1.f);
763 766
764 // Fade out the widget. This animation continues past the lifetime of |this|. 767 // Fade out the widget. This animation continues past the lifetime of |this|.
765 WmWindow* widget_window = WmLookup::Get()->GetWindowForWidget(widget.get()); 768 WmWindow* widget_window = WmLookup::Get()->GetWindowForWidget(widget.get());
766 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = 769 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings =
767 ScopedOverviewAnimationSettingsFactory::Get() 770 ScopedOverviewAnimationSettingsFactory::Get()
768 ->CreateOverviewAnimationSettings( 771 ->CreateOverviewAnimationSettings(
(...skipping 16 matching lines...) Expand all
785 788
786 gfx::SlideAnimation* WindowSelectorItem::GetBackgroundViewAnimation() { 789 gfx::SlideAnimation* WindowSelectorItem::GetBackgroundViewAnimation() {
787 return background_view_ ? background_view_->animation() : nullptr; 790 return background_view_ ? background_view_->animation() : nullptr;
788 } 791 }
789 792
790 WmWindow* WindowSelectorItem::GetOverviewWindowForMinimizedStateForTest() { 793 WmWindow* WindowSelectorItem::GetOverviewWindowForMinimizedStateForTest() {
791 return transform_window_.GetOverviewWindowForMinimizedState(); 794 return transform_window_.GetOverviewWindowForMinimizedState();
792 } 795 }
793 796
794 } // namespace ash 797 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/overview/window_selector_item.h ('k') | ash/wm/overview/window_selector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698