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

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

Issue 810033010: Remove TransparentActivateWindowButton from Overview Mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed nits Created 5 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
« no previous file with comments | « ash/wm/overview/window_selector_item.h ('k') | ash/wm/overview/window_selector_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/screen_util.h" 10 #include "ash/screen_util.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/shell_window_ids.h" 12 #include "ash/shell_window_ids.h"
13 #include "ash/wm/overview/overview_animation_type.h" 13 #include "ash/wm/overview/overview_animation_type.h"
14 #include "ash/wm/overview/overview_window_button.h"
14 #include "ash/wm/overview/scoped_overview_animation_settings.h" 15 #include "ash/wm/overview/scoped_overview_animation_settings.h"
15 #include "ash/wm/overview/scoped_transform_overview_window.h" 16 #include "ash/wm/overview/scoped_transform_overview_window.h"
16 #include "ash/wm/overview/window_selector_controller.h" 17 #include "ash/wm/overview/window_selector_controller.h"
17 #include "ash/wm/window_state.h"
18 #include "base/auto_reset.h" 18 #include "base/auto_reset.h"
19 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
20 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
21 #include "base/time/time.h" 21 #include "base/time/time.h"
22 #include "grit/ash_resources.h" 22 #include "grit/ash_resources.h"
23 #include "grit/ash_strings.h" 23 #include "grit/ash_strings.h"
24 #include "ui/aura/window.h" 24 #include "ui/aura/window.h"
25 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
26 #include "ui/base/resource/resource_bundle.h" 26 #include "ui/base/resource/resource_bundle.h"
27 #include "ui/gfx/geometry/vector2d.h" 27 #include "ui/gfx/geometry/vector2d.h"
28 #include "ui/gfx/transform_util.h" 28 #include "ui/gfx/transform_util.h"
29 #include "ui/strings/grit/ui_strings.h" 29 #include "ui/strings/grit/ui_strings.h"
30 #include "ui/views/controls/button/image_button.h" 30 #include "ui/views/controls/button/image_button.h"
31 #include "ui/views/controls/label.h"
32 #include "ui/views/layout/box_layout.h" 31 #include "ui/views/layout/box_layout.h"
33 #include "ui/views/widget/widget.h" 32 #include "ui/views/widget/widget.h"
34 #include "ui/wm/core/window_util.h" 33 #include "ui/wm/core/window_util.h"
35 34
36 namespace ash { 35 namespace ash {
37 36
38 namespace { 37 namespace {
39 38
40 // In the conceptual overview table, the window margin is the space reserved 39 // In the conceptual overview table, the window margin is the space reserved
41 // around the window within the cell. This margin does not overlap so the 40 // around the window within the cell. This margin does not overlap so the
42 // closest distance between adjacent windows will be twice this amount. 41 // closest distance between adjacent windows will be twice this amount.
43 static const int kWindowMargin = 30; 42 static const int kWindowMargin = 30;
44 43
45 // Foreground label color.
46 static const SkColor kLabelColor = SK_ColorWHITE;
47
48 // Background label color.
49 static const SkColor kLabelBackground = SK_ColorTRANSPARENT;
50
51 // Label shadow color.
52 static const SkColor kLabelShadow = 0xB0000000;
53
54 // Vertical padding for the label, both over and beneath it.
55 static const int kVerticalLabelPadding = 20;
56
57 // Solid shadow length from the label
58 static const int kVerticalShadowOffset = 1;
59
60 // Amount of blur applied to the label shadow
61 static const int kShadowBlur = 10;
62
63 // Opacity for dimmed items. 44 // Opacity for dimmed items.
64 static const float kDimmedItemOpacity = 0.5f; 45 static const float kDimmedItemOpacity = 0.5f;
65 46
66 // Calculates the |window| bounds after being transformed to the selector's 47 // Calculates the |window| bounds after being transformed to the selector's
67 // space. The returned Rect is in virtual screen coordinates. 48 // space. The returned Rect is in virtual screen coordinates.
68 gfx::Rect GetTransformedBounds(aura::Window* window) { 49 gfx::Rect GetTransformedBounds(aura::Window* window) {
69 gfx::RectF bounds(ScreenUtil::ConvertRectToScreen(window->GetRootWindow(), 50 gfx::RectF bounds(ScreenUtil::ConvertRectToScreen(window->GetRootWindow(),
70 window->layer()->GetTargetBounds())); 51 window->layer()->GetTargetBounds()));
71 gfx::Transform new_transform = TransformAboutPivot( 52 gfx::Transform new_transform = TransformAboutPivot(
72 gfx::Point(bounds.x(), bounds.y()), 53 gfx::Point(bounds.x(), bounds.y()),
73 window->layer()->GetTargetTransform()); 54 window->layer()->GetTargetTransform());
74 new_transform.TransformRect(&bounds); 55 new_transform.TransformRect(&bounds);
75 return ToEnclosingRect(bounds); 56 return ToEnclosingRect(bounds);
76 } 57 }
77 58
78 // Convenvience method to fade in a Window with predefined animation settings.
79 // Note: The fade in animation will occur after a delay where the delay is how
80 // long the lay out animations take.
81 void SetupFadeInAfterLayout(aura::Window* window) {
82 ui::Layer* layer = window->layer();
83 layer->SetOpacity(0.0f);
84 ScopedOverviewAnimationSettings animation_settings(
85 OverviewAnimationType::OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN,
86 window);
87 layer->SetOpacity(1.0f);
88 }
89
90 // An image button with a close window icon. 59 // An image button with a close window icon.
91 class OverviewCloseButton : public views::ImageButton { 60 class OverviewCloseButton : public views::ImageButton {
92 public: 61 public:
93 explicit OverviewCloseButton(views::ButtonListener* listener); 62 explicit OverviewCloseButton(views::ButtonListener* listener);
94 ~OverviewCloseButton() override; 63 ~OverviewCloseButton() override;
95 64
96 private: 65 private:
97 DISALLOW_COPY_AND_ASSIGN(OverviewCloseButton); 66 DISALLOW_COPY_AND_ASSIGN(OverviewCloseButton);
98 }; 67 };
99 68
(...skipping 11 matching lines...) Expand all
111 OverviewCloseButton::~OverviewCloseButton() { 80 OverviewCloseButton::~OverviewCloseButton() {
112 } 81 }
113 82
114 } // namespace 83 } // namespace
115 84
116 WindowSelectorItem::WindowSelectorItem(aura::Window* window) 85 WindowSelectorItem::WindowSelectorItem(aura::Window* window)
117 : dimmed_(false), 86 : dimmed_(false),
118 root_window_(window->GetRootWindow()), 87 root_window_(window->GetRootWindow()),
119 transform_window_(window), 88 transform_window_(window),
120 in_bounds_update_(false), 89 in_bounds_update_(false),
121 window_label_view_(nullptr),
122 close_button_(new OverviewCloseButton(this)), 90 close_button_(new OverviewCloseButton(this)),
123 selector_item_activate_window_button_( 91 overview_window_button_(new OverviewWindowButton(window)) {
124 new TransparentActivateWindowButton(root_window_, this)) {
125 views::Widget::InitParams params; 92 views::Widget::InitParams params;
126 params.type = views::Widget::InitParams::TYPE_POPUP; 93 params.type = views::Widget::InitParams::TYPE_POPUP;
127 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 94 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
128 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 95 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
129 params.parent = Shell::GetContainer(root_window_, 96 params.parent = Shell::GetContainer(root_window_,
130 kShellWindowId_OverlayContainer); 97 kShellWindowId_OverlayContainer);
131 close_button_widget_.set_focus_on_creation(false); 98 close_button_widget_.set_focus_on_creation(false);
132 close_button_widget_.Init(params); 99 close_button_widget_.Init(params);
133 close_button_->SetVisible(false); 100 close_button_->SetVisible(false);
134 close_button_widget_.SetContentsView(close_button_); 101 close_button_widget_.SetContentsView(close_button_);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 return transform_window_.Contains(target); 139 return transform_window_.Contains(target);
173 } 140 }
174 141
175 void WindowSelectorItem::SetBounds(const gfx::Rect& target_bounds, 142 void WindowSelectorItem::SetBounds(const gfx::Rect& target_bounds,
176 OverviewAnimationType animation_type) { 143 OverviewAnimationType animation_type) {
177 if (in_bounds_update_) 144 if (in_bounds_update_)
178 return; 145 return;
179 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true); 146 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true);
180 target_bounds_ = target_bounds; 147 target_bounds_ = target_bounds;
181 148
182 UpdateWindowLabels(target_bounds, animation_type); 149 overview_window_button_->SetBounds(target_bounds, animation_type);
183 150
184 gfx::Rect inset_bounds(target_bounds); 151 gfx::Rect inset_bounds(target_bounds);
185 inset_bounds.Inset(kWindowMargin, kWindowMargin); 152 inset_bounds.Inset(kWindowMargin, kWindowMargin);
186 SetItemBounds(inset_bounds, animation_type); 153 SetItemBounds(inset_bounds, animation_type);
187 154
188 // SetItemBounds is called before UpdateCloseButtonLayout so the close button 155 // SetItemBounds is called before UpdateCloseButtonLayout so the close button
189 // can properly use the updated windows bounds. 156 // can properly use the updated windows bounds.
190 UpdateCloseButtonLayout(animation_type); 157 UpdateCloseButtonLayout(animation_type);
191 UpdateSelectorButtons();
192 } 158 }
193 159
194 void WindowSelectorItem::RecomputeWindowTransforms() { 160 void WindowSelectorItem::RecomputeWindowTransforms() {
195 if (in_bounds_update_ || target_bounds_.IsEmpty()) 161 if (in_bounds_update_ || target_bounds_.IsEmpty())
196 return; 162 return;
197 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true); 163 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true);
198 gfx::Rect inset_bounds(target_bounds_); 164 gfx::Rect inset_bounds(target_bounds_);
199 inset_bounds.Inset(kWindowMargin, kWindowMargin); 165 inset_bounds.Inset(kWindowMargin, kWindowMargin);
200 SetItemBounds(inset_bounds, OverviewAnimationType::OVERVIEW_ANIMATION_NONE); 166 SetItemBounds(inset_bounds, OverviewAnimationType::OVERVIEW_ANIMATION_NONE);
201
202 UpdateCloseButtonLayout(OverviewAnimationType::OVERVIEW_ANIMATION_NONE); 167 UpdateCloseButtonLayout(OverviewAnimationType::OVERVIEW_ANIMATION_NONE);
203 UpdateSelectorButtons();
204 } 168 }
205 169
206 void WindowSelectorItem::SendFocusAlert() const { 170 void WindowSelectorItem::SendFocusAlert() const {
207 selector_item_activate_window_button_->SendFocusAlert(); 171 overview_window_button_->SendFocusAlert();
208 } 172 }
209 173
210 void WindowSelectorItem::SetDimmed(bool dimmed) { 174 void WindowSelectorItem::SetDimmed(bool dimmed) {
211 dimmed_ = dimmed; 175 dimmed_ = dimmed;
212 SetOpacity(dimmed ? kDimmedItemOpacity : 1.0f); 176 SetOpacity(dimmed ? kDimmedItemOpacity : 1.0f);
213 } 177 }
214 178
215 void WindowSelectorItem::ButtonPressed(views::Button* sender, 179 void WindowSelectorItem::ButtonPressed(views::Button* sender,
216 const ui::Event& event) { 180 const ui::Event& event) {
217 transform_window_.Close(); 181 transform_window_.Close();
218 } 182 }
219 183
220 void WindowSelectorItem::OnWindowDestroying(aura::Window* window) { 184 void WindowSelectorItem::OnWindowDestroying(aura::Window* window) {
221 window->RemoveObserver(this); 185 window->RemoveObserver(this);
222 transform_window_.OnWindowDestroyed(); 186 transform_window_.OnWindowDestroyed();
223 } 187 }
224 188
225 void WindowSelectorItem::OnWindowTitleChanged(aura::Window* window) { 189 void WindowSelectorItem::OnWindowTitleChanged(aura::Window* window) {
226 // TODO(flackr): Maybe add the new title to a vector of titles so that we can 190 // TODO(flackr): Maybe add the new title to a vector of titles so that we can
227 // filter any of the titles the window had while in the overview session. 191 // filter any of the titles the window had while in the overview session.
228 if (window == GetWindow()) { 192 overview_window_button_->SetLabelText(window->title());
229 window_label_view_->SetText(window->title()); 193 UpdateCloseButtonAccessibilityName();
230 UpdateCloseButtonAccessibilityName();
231 }
232 UpdateCloseButtonLayout(OverviewAnimationType::OVERVIEW_ANIMATION_NONE);
233 UpdateSelectorButtons();
234 }
235
236 void WindowSelectorItem::Select() {
237 aura::Window* selection_window = GetWindow();
238 if (selection_window)
239 wm::GetWindowState(selection_window)->Activate();
240 } 194 }
241 195
242 void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds, 196 void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds,
243 OverviewAnimationType animation_type) { 197 OverviewAnimationType animation_type) {
244 DCHECK(root_window_ == GetWindow()->GetRootWindow()); 198 DCHECK(root_window_ == GetWindow()->GetRootWindow());
245 gfx::Rect screen_bounds = transform_window_.GetTargetBoundsInScreen(); 199 gfx::Rect screen_bounds = transform_window_.GetTargetBoundsInScreen();
246 gfx::Rect selector_item_bounds = 200 gfx::Rect selector_item_bounds =
247 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio( 201 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio(
248 screen_bounds, target_bounds); 202 screen_bounds, target_bounds);
249 gfx::Transform transform = 203 gfx::Transform transform =
250 ScopedTransformOverviewWindow::GetTransformForRect(screen_bounds, 204 ScopedTransformOverviewWindow::GetTransformForRect(screen_bounds,
251 selector_item_bounds); 205 selector_item_bounds);
252 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; 206 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings;
253 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); 207 transform_window_.BeginScopedAnimation(animation_type, &animation_settings);
254 transform_window_.SetTransform(root_window_, transform); 208 transform_window_.SetTransform(root_window_, transform);
255 transform_window_.set_overview_transform(transform); 209 transform_window_.set_overview_transform(transform);
256 } 210 }
257 211
258 void WindowSelectorItem::SetOpacity(float opacity) { 212 void WindowSelectorItem::SetOpacity(float opacity) {
259 window_label_->GetNativeWindow()->layer()->SetOpacity(opacity); 213 overview_window_button_->SetOpacity(opacity);
260 close_button_widget_.GetNativeWindow()->layer()->SetOpacity(opacity); 214 close_button_widget_.GetNativeWindow()->layer()->SetOpacity(opacity);
261 215
262 transform_window_.SetOpacity(opacity); 216 transform_window_.SetOpacity(opacity);
263 } 217 }
264 218
265 void WindowSelectorItem::UpdateWindowLabels(
266 const gfx::Rect& window_bounds,
267 OverviewAnimationType animation_type) {
268
269 if (!window_label_) {
270 CreateWindowLabel(GetWindow()->title());
271 SetupFadeInAfterLayout(window_label_->GetNativeWindow());
272 }
273
274 gfx::Rect converted_bounds = ScreenUtil::ConvertRectFromScreen(root_window_,
275 window_bounds);
276 gfx::Rect label_bounds(converted_bounds.x(),
277 converted_bounds.bottom(),
278 converted_bounds.width(),
279 0);
280 label_bounds.set_height(window_label_->GetContentsView()->
281 GetPreferredSize().height());
282 label_bounds.set_y(label_bounds.y() - window_label_->
283 GetContentsView()->GetPreferredSize().height());
284
285 ScopedOverviewAnimationSettings animation_settings(animation_type,
286 window_label_->GetNativeWindow());
287
288 window_label_->GetNativeWindow()->SetBounds(label_bounds);
289 }
290
291 void WindowSelectorItem::CreateWindowLabel(const base::string16& title) {
292 window_label_.reset(new views::Widget);
293 views::Widget::InitParams params;
294 params.type = views::Widget::InitParams::TYPE_POPUP;
295 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
296 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
297 params.parent = Shell::GetContainer(root_window_,
298 kShellWindowId_OverlayContainer);
299 params.accept_events = false;
300 params.visible_on_all_workspaces = true;
301 window_label_->set_focus_on_creation(false);
302 window_label_->Init(params);
303 window_label_view_ = new views::Label;
304 window_label_view_->SetEnabledColor(kLabelColor);
305 window_label_view_->SetBackgroundColor(kLabelBackground);
306 window_label_view_->SetShadows(gfx::ShadowValues(
307 1,
308 gfx::ShadowValue(
309 gfx::Point(0, kVerticalShadowOffset), kShadowBlur, kLabelShadow)));
310 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
311 window_label_view_->SetFontList(
312 bundle.GetFontList(ui::ResourceBundle::BoldFont));
313 window_label_view_->SetText(title);
314 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kVertical,
315 0,
316 kVerticalLabelPadding,
317 0);
318 window_label_view_->SetLayoutManager(layout);
319 window_label_->SetContentsView(window_label_view_);
320 window_label_->Show();
321 }
322
323 void WindowSelectorItem::UpdateSelectorButtons() {
324 aura::Window* window = GetWindow();
325
326 selector_item_activate_window_button_->SetBounds(target_bounds());
327 selector_item_activate_window_button_->SetAccessibleName(window->title());
328
329 TransparentActivateWindowButton* activate_button =
330 transform_window_.activate_button();
331 activate_button->SetBounds(target_bounds());
332 activate_button->SetAccessibleName(window->title());
333 }
334
335 void WindowSelectorItem::UpdateCloseButtonLayout( 219 void WindowSelectorItem::UpdateCloseButtonLayout(
336 OverviewAnimationType animation_type) { 220 OverviewAnimationType animation_type) {
337 if (!close_button_->visible()) { 221 if (!close_button_->visible()) {
338 close_button_->SetVisible(true); 222 close_button_->SetVisible(true);
339 SetupFadeInAfterLayout(close_button_widget_.GetNativeWindow()); 223 ScopedOverviewAnimationSettings::SetupFadeInAfterLayout(
224 close_button_widget_.GetNativeWindow());
340 } 225 }
341 ScopedOverviewAnimationSettings animation_settings(animation_type, 226 ScopedOverviewAnimationSettings animation_settings(animation_type,
342 close_button_widget_.GetNativeWindow()); 227 close_button_widget_.GetNativeWindow());
343 228
344 gfx::Rect transformed_window_bounds = ScreenUtil::ConvertRectFromScreen( 229 gfx::Rect transformed_window_bounds = ScreenUtil::ConvertRectFromScreen(
345 close_button_widget_.GetNativeWindow()->GetRootWindow(), 230 close_button_widget_.GetNativeWindow()->GetRootWindow(),
346 GetTransformedBounds(GetWindow())); 231 GetTransformedBounds(GetWindow()));
347 232
348 gfx::Transform close_button_transform; 233 gfx::Transform close_button_transform;
349 close_button_transform.Translate(transformed_window_bounds.right(), 234 close_button_transform.Translate(transformed_window_bounds.right(),
350 transformed_window_bounds.y()); 235 transformed_window_bounds.y());
351 close_button_widget_.GetNativeWindow()->SetTransform( 236 close_button_widget_.GetNativeWindow()->SetTransform(
352 close_button_transform); 237 close_button_transform);
353 } 238 }
354 239
355 void WindowSelectorItem::UpdateCloseButtonAccessibilityName() { 240 void WindowSelectorItem::UpdateCloseButtonAccessibilityName() {
356 close_button_->SetAccessibleName(l10n_util::GetStringFUTF16( 241 close_button_->SetAccessibleName(l10n_util::GetStringFUTF16(
357 IDS_ASH_OVERVIEW_CLOSE_ITEM_BUTTON_ACCESSIBLE_NAME, 242 IDS_ASH_OVERVIEW_CLOSE_ITEM_BUTTON_ACCESSIBLE_NAME,
358 GetWindow()->title())); 243 GetWindow()->title()));
359 } 244 }
360 245
361 } // namespace ash 246 } // namespace ash
OLDNEW
« no previous file with comments | « ash/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