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

Side by Side Diff: ash/wm/workspace/phantom_window_controller.cc

Issue 1933303002: Moves windowsresizers to ash/wm/common (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: WorkspaceWindowResizer Created 4 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/wm/workspace/phantom_window_controller.h"
6
7 #include <math.h>
8
9 #include "ash/wm/common/root_window_finder.h"
10 #include "ash/wm/common/wm_root_window_controller.h"
11 #include "ash/wm/common/wm_shell_window_ids.h"
12 #include "ash/wm/common/wm_window.h"
13 #include "grit/ash_resources.h"
14 #include "ui/compositor/layer.h"
15 #include "ui/compositor/scoped_layer_animation_settings.h"
16 #include "ui/views/background.h"
17 #include "ui/views/painter.h"
18 #include "ui/views/view.h"
19 #include "ui/views/widget/widget.h"
20
21 namespace ash {
22 namespace {
23
24 // The duration of the show animation.
25 const int kAnimationDurationMs = 200;
26
27 // The size of the phantom window at the beginning of the show animation in
28 // relation to the size of the phantom window at the end of the animation.
29 const float kStartBoundsRatio = 0.85f;
30
31 // The amount of pixels that the phantom window's shadow should extend past
32 // the bounds passed into Show().
33 const int kShadowThickness = 15;
34
35 // The minimum size of a phantom window including the shadow. The minimum size
36 // is derived from the size of the IDR_AURA_PHANTOM_WINDOW image assets.
37 const int kMinSizeWithShadow = 100;
38
39 // Adjusts the phantom window's bounds so that the bounds:
40 // - Include the size of the shadow.
41 // - Have a size equal to or larger than the minimum phantom window size.
42 gfx::Rect GetAdjustedBounds(const gfx::Rect& bounds) {
43 int x_inset = std::max(
44 static_cast<int>(ceil((kMinSizeWithShadow - bounds.width()) / 2.0f)),
45 kShadowThickness);
46 int y_inset = std::max(
47 static_cast<int>(ceil((kMinSizeWithShadow - bounds.height()) / 2.0f)),
48 kShadowThickness);
49
50 gfx::Rect adjusted_bounds(bounds);
51 adjusted_bounds.Inset(-x_inset, -y_inset);
52 return adjusted_bounds;
53 }
54
55 // Starts an animation of |widget| to |new_bounds_in_screen|. No-op if |widget|
56 // is NULL.
57 void AnimateToBounds(views::Widget* widget,
58 const gfx::Rect& new_bounds_in_screen) {
59 if (!widget)
60 return;
61
62 ui::ScopedLayerAnimationSettings scoped_setter(
63 wm::WmWindow::Get(widget)->GetLayer()->GetAnimator());
64 scoped_setter.SetTweenType(gfx::Tween::EASE_IN);
65 scoped_setter.SetPreemptionStrategy(
66 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
67 scoped_setter.SetTransitionDuration(
68 base::TimeDelta::FromMilliseconds(kAnimationDurationMs));
69 widget->SetBounds(new_bounds_in_screen);
70 }
71
72 } // namespace
73
74 // PhantomWindowController ----------------------------------------------------
75
76 PhantomWindowController::PhantomWindowController(wm::WmWindow* window)
77 : window_(window) {}
78
79 PhantomWindowController::~PhantomWindowController() {
80 }
81
82 void PhantomWindowController::Show(const gfx::Rect& bounds_in_screen) {
83 gfx::Rect adjusted_bounds_in_screen = GetAdjustedBounds(bounds_in_screen);
84 if (adjusted_bounds_in_screen == target_bounds_in_screen_)
85 return;
86 target_bounds_in_screen_ = adjusted_bounds_in_screen;
87
88 gfx::Rect start_bounds_in_screen = target_bounds_in_screen_;
89 int start_width = std::max(
90 kMinSizeWithShadow,
91 static_cast<int>(start_bounds_in_screen.width() * kStartBoundsRatio));
92 int start_height = std::max(
93 kMinSizeWithShadow,
94 static_cast<int>(start_bounds_in_screen.height() * kStartBoundsRatio));
95 start_bounds_in_screen.Inset(
96 floor((start_bounds_in_screen.width() - start_width) / 2.0f),
97 floor((start_bounds_in_screen.height() - start_height) / 2.0f));
98 phantom_widget_ =
99 CreatePhantomWidget(wm::GetRootWindowMatching(target_bounds_in_screen_),
100 start_bounds_in_screen);
101
102 AnimateToBounds(phantom_widget_.get(), target_bounds_in_screen_);
103 }
104
105 std::unique_ptr<views::Widget> PhantomWindowController::CreatePhantomWidget(
106 wm::WmWindow* root_window,
107 const gfx::Rect& bounds_in_screen) {
108 std::unique_ptr<views::Widget> phantom_widget(new views::Widget);
109 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
110 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
111 // PhantomWindowController is used by FrameMaximizeButton to highlight the
112 // launcher button. Put the phantom in the same window as the launcher so that
113 // the phantom is visible.
114 params.keep_on_top = true;
115 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
116 root_window->GetRootWindowController()->ConfigureWidgetInitParamsForContainer(
117 phantom_widget.get(), kShellWindowId_ShelfContainer, &params);
118 phantom_widget->set_focus_on_creation(false);
119 phantom_widget->Init(params);
120 phantom_widget->SetVisibilityChangedAnimationsEnabled(false);
121 wm::WmWindow* phantom_widget_window = wm::WmWindow::Get(phantom_widget.get());
122 phantom_widget_window->SetName("PhantomWindow");
123 phantom_widget_window->SetShellWindowId(kShellWindowId_PhantomWindow);
124 phantom_widget->SetBounds(bounds_in_screen);
125 // TODO(sky): I suspect this is never true, verify that.
126 if (phantom_widget_window->GetParent() == window_->GetParent()) {
127 phantom_widget_window->GetParent()->StackChildAbove(phantom_widget_window,
128 window_);
129 }
130
131 const int kImages[] = IMAGE_GRID(IDR_AURA_PHANTOM_WINDOW);
132 views::Painter* background_painter =
133 views::Painter::CreateImageGridPainter(kImages);
134 views::View* content_view = new views::View;
135 content_view->set_background(
136 views::Background::CreateBackgroundPainter(true, background_painter));
137 phantom_widget->SetContentsView(content_view);
138
139 // Show the widget after all the setups.
140 phantom_widget->Show();
141
142 // Fade the window in.
143 ui::Layer* widget_layer = phantom_widget_window->GetLayer();
144 widget_layer->SetOpacity(0);
145 ui::ScopedLayerAnimationSettings scoped_setter(widget_layer->GetAnimator());
146 scoped_setter.SetTransitionDuration(
147 base::TimeDelta::FromMilliseconds(kAnimationDurationMs));
148 widget_layer->SetOpacity(1);
149
150 return phantom_widget;
151 }
152
153 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698