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

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

Issue 872113004: Modified OverviewMode's LabelButton bounds to cover the entire item. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed unnecessary changes from unittests Created 5 years, 10 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/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"
15 #include "ash/wm/overview/scoped_overview_animation_settings.h" 14 #include "ash/wm/overview/scoped_overview_animation_settings.h"
16 #include "ash/wm/overview/scoped_transform_overview_window.h" 15 #include "ash/wm/overview/scoped_transform_overview_window.h"
17 #include "ash/wm/overview/window_selector_controller.h" 16 #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/border.h"
30 #include "ui/views/controls/button/image_button.h" 31 #include "ui/views/controls/button/image_button.h"
32 #include "ui/views/controls/button/label_button.h"
31 #include "ui/views/layout/box_layout.h" 33 #include "ui/views/layout/box_layout.h"
32 #include "ui/views/widget/widget.h" 34 #include "ui/views/widget/widget.h"
33 #include "ui/wm/core/window_util.h" 35 #include "ui/wm/core/window_util.h"
34 36
35 namespace ash { 37 namespace ash {
36 38
37 namespace { 39 namespace {
38 40
39 // In the conceptual overview table, the window margin is the space reserved 41 // In the conceptual overview table, the window margin is the space reserved
40 // around the window within the cell. This margin does not overlap so the 42 // around the window within the cell. This margin does not overlap so the
41 // closest distance between adjacent windows will be twice this amount. 43 // closest distance between adjacent windows will be twice this amount.
42 static const int kWindowMargin = 30; 44 static const int kWindowMargin = 30;
43 45
46 // Foreground label color.
47 static const SkColor kLabelColor = SK_ColorWHITE;
48
49 // Label shadow color.
50 static const SkColor kLabelShadow = 0xB0000000;
51
52 // Vertical padding for the label, on top of it.
53 static const int kVerticalLabelPadding = 20;
54
55 // Solid shadow length from the label
56 static const int kVerticalShadowOffset = 1;
57
58 // Amount of blur applied to the label shadow
59 static const int kShadowBlur = 10;
60
44 // Opacity for dimmed items. 61 // Opacity for dimmed items.
45 static const float kDimmedItemOpacity = 0.5f; 62 static const float kDimmedItemOpacity = 0.5f;
46 63
47 // Calculates the |window| bounds after being transformed to the selector's 64 // Calculates the |window| bounds after being transformed to the selector's
48 // space. The returned Rect is in virtual screen coordinates. 65 // space. The returned Rect is in virtual screen coordinates.
49 gfx::Rect GetTransformedBounds(aura::Window* window) { 66 gfx::Rect GetTransformedBounds(aura::Window* window) {
50 gfx::RectF bounds(ScreenUtil::ConvertRectToScreen(window->GetRootWindow(), 67 gfx::RectF bounds(ScreenUtil::ConvertRectToScreen(window->GetRootWindow(),
51 window->layer()->GetTargetBounds())); 68 window->layer()->GetTargetBounds()));
52 gfx::Transform new_transform = TransformAboutPivot( 69 gfx::Transform new_transform = TransformAboutPivot(
53 gfx::Point(bounds.x(), bounds.y()), 70 gfx::Point(bounds.x(), bounds.y()),
(...skipping 26 matching lines...) Expand all
80 OverviewCloseButton::~OverviewCloseButton() { 97 OverviewCloseButton::~OverviewCloseButton() {
81 } 98 }
82 99
83 } // namespace 100 } // namespace
84 101
85 WindowSelectorItem::WindowSelectorItem(aura::Window* window) 102 WindowSelectorItem::WindowSelectorItem(aura::Window* window)
86 : dimmed_(false), 103 : dimmed_(false),
87 root_window_(window->GetRootWindow()), 104 root_window_(window->GetRootWindow()),
88 transform_window_(window), 105 transform_window_(window),
89 in_bounds_update_(false), 106 in_bounds_update_(false),
90 close_button_(new OverviewCloseButton(this)), 107 window_label_button_view_(nullptr),
91 overview_window_button_(new OverviewWindowButton(window)) { 108 close_button_(new OverviewCloseButton(this)) {
109 CreateWindowLabel(window->title());
92 views::Widget::InitParams params; 110 views::Widget::InitParams params;
93 params.type = views::Widget::InitParams::TYPE_POPUP; 111 params.type = views::Widget::InitParams::TYPE_POPUP;
94 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 112 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
95 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 113 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
96 params.parent = Shell::GetContainer(root_window_, 114 params.parent = Shell::GetContainer(root_window_,
97 kShellWindowId_OverlayContainer); 115 kShellWindowId_OverlayContainer);
98 close_button_widget_.set_focus_on_creation(false); 116 close_button_widget_.set_focus_on_creation(false);
99 close_button_widget_.Init(params); 117 close_button_widget_.Init(params);
100 close_button_->SetVisible(false); 118 close_button_->SetVisible(false);
101 close_button_widget_.SetContentsView(close_button_); 119 close_button_widget_.SetContentsView(close_button_);
102 close_button_widget_.SetSize(close_button_->GetPreferredSize()); 120 close_button_widget_.SetSize(close_button_->GetPreferredSize());
103 close_button_widget_.Show(); 121 close_button_widget_.Show();
104 122
105 gfx::Rect close_button_rect(close_button_widget_.GetNativeWindow()->bounds()); 123 gfx::Rect close_button_rect(close_button_widget_.GetNativeWindow()->bounds());
106 // Align the center of the button with position (0, 0) so that the 124 // Align the center of the button with position (0, 0) so that the
107 // translate transform does not need to take the button dimensions into 125 // translate transform does not need to take the button dimensions into
108 // account. 126 // account.
109 close_button_rect.set_x(-close_button_rect.width() / 2); 127 close_button_rect.set_x(-close_button_rect.width() / 2);
110 close_button_rect.set_y(-close_button_rect.height() / 2); 128 close_button_rect.set_y(-close_button_rect.height() / 2);
111 close_button_widget_.GetNativeWindow()->SetBounds(close_button_rect); 129 close_button_widget_.GetNativeWindow()->SetBounds(close_button_rect);
112 130
113 GetWindow()->AddObserver(this); 131 GetWindow()->AddObserver(this);
114
115 UpdateCloseButtonAccessibilityName();
116 } 132 }
117 133
118 WindowSelectorItem::~WindowSelectorItem() { 134 WindowSelectorItem::~WindowSelectorItem() {
119 GetWindow()->RemoveObserver(this); 135 GetWindow()->RemoveObserver(this);
120 } 136 }
121 137
122 aura::Window* WindowSelectorItem::GetWindow() { 138 aura::Window* WindowSelectorItem::GetWindow() {
123 return transform_window_.window(); 139 return transform_window_.window();
124 } 140 }
125 141
(...skipping 13 matching lines...) Expand all
139 return transform_window_.Contains(target); 155 return transform_window_.Contains(target);
140 } 156 }
141 157
142 void WindowSelectorItem::SetBounds(const gfx::Rect& target_bounds, 158 void WindowSelectorItem::SetBounds(const gfx::Rect& target_bounds,
143 OverviewAnimationType animation_type) { 159 OverviewAnimationType animation_type) {
144 if (in_bounds_update_) 160 if (in_bounds_update_)
145 return; 161 return;
146 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true); 162 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true);
147 target_bounds_ = target_bounds; 163 target_bounds_ = target_bounds;
148 164
149 overview_window_button_->SetBounds(target_bounds, animation_type);
150
151 gfx::Rect inset_bounds(target_bounds); 165 gfx::Rect inset_bounds(target_bounds);
152 inset_bounds.Inset(kWindowMargin, kWindowMargin); 166 inset_bounds.Inset(kWindowMargin, kWindowMargin);
153 SetItemBounds(inset_bounds, animation_type); 167 SetItemBounds(inset_bounds, animation_type);
154 168
155 // SetItemBounds is called before UpdateCloseButtonLayout so the close button 169 // SetItemBounds is called before UpdateCloseButtonLayout so the close button
156 // can properly use the updated windows bounds. 170 // can properly use the updated windows bounds.
157 UpdateCloseButtonLayout(animation_type); 171 UpdateCloseButtonLayout(animation_type);
172 UpdateWindowLabel(target_bounds, animation_type);
158 } 173 }
159 174
160 void WindowSelectorItem::RecomputeWindowTransforms() { 175 void WindowSelectorItem::RecomputeWindowTransforms() {
161 if (in_bounds_update_ || target_bounds_.IsEmpty()) 176 if (in_bounds_update_ || target_bounds_.IsEmpty())
162 return; 177 return;
163 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true); 178 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true);
164 gfx::Rect inset_bounds(target_bounds_); 179 gfx::Rect inset_bounds(target_bounds_);
165 inset_bounds.Inset(kWindowMargin, kWindowMargin); 180 inset_bounds.Inset(kWindowMargin, kWindowMargin);
166 SetItemBounds(inset_bounds, OverviewAnimationType::OVERVIEW_ANIMATION_NONE); 181 SetItemBounds(inset_bounds, OverviewAnimationType::OVERVIEW_ANIMATION_NONE);
167 UpdateCloseButtonLayout(OverviewAnimationType::OVERVIEW_ANIMATION_NONE); 182 UpdateCloseButtonLayout(OverviewAnimationType::OVERVIEW_ANIMATION_NONE);
168 } 183 }
169 184
170 void WindowSelectorItem::SendFocusAlert() const { 185 void WindowSelectorItem::SendFocusAlert() const {
171 overview_window_button_->SendFocusAlert(); 186 window_label_button_view_->NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, true);
172 } 187 }
173 188
174 void WindowSelectorItem::SetDimmed(bool dimmed) { 189 void WindowSelectorItem::SetDimmed(bool dimmed) {
175 dimmed_ = dimmed; 190 dimmed_ = dimmed;
176 SetOpacity(dimmed ? kDimmedItemOpacity : 1.0f); 191 SetOpacity(dimmed ? kDimmedItemOpacity : 1.0f);
177 } 192 }
178 193
179 void WindowSelectorItem::ButtonPressed(views::Button* sender, 194 void WindowSelectorItem::ButtonPressed(views::Button* sender,
180 const ui::Event& event) { 195 const ui::Event& event) {
181 transform_window_.Close(); 196 if (sender == close_button_) {
197 transform_window_.Close();
198 return;
199 }
200 CHECK(sender == window_label_button_view_);
201 wm::GetWindowState(transform_window_.window())->Activate();
182 } 202 }
183 203
184 void WindowSelectorItem::OnWindowDestroying(aura::Window* window) { 204 void WindowSelectorItem::OnWindowDestroying(aura::Window* window) {
185 window->RemoveObserver(this); 205 window->RemoveObserver(this);
186 transform_window_.OnWindowDestroyed(); 206 transform_window_.OnWindowDestroyed();
187 } 207 }
188 208
189 void WindowSelectorItem::OnWindowTitleChanged(aura::Window* window) { 209 void WindowSelectorItem::OnWindowTitleChanged(aura::Window* window) {
190 // TODO(flackr): Maybe add the new title to a vector of titles so that we can 210 // TODO(flackr): Maybe add the new title to a vector of titles so that we can
191 // filter any of the titles the window had while in the overview session. 211 // filter any of the titles the window had while in the overview session.
192 overview_window_button_->SetLabelText(window->title()); 212 window_label_button_view_->SetText(window->title());
193 UpdateCloseButtonAccessibilityName(); 213 UpdateCloseButtonAccessibilityName();
194 } 214 }
195 215
196 void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds, 216 void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds,
197 OverviewAnimationType animation_type) { 217 OverviewAnimationType animation_type) {
198 DCHECK(root_window_ == GetWindow()->GetRootWindow()); 218 DCHECK(root_window_ == GetWindow()->GetRootWindow());
199 gfx::Rect screen_bounds = transform_window_.GetTargetBoundsInScreen(); 219 gfx::Rect screen_bounds = transform_window_.GetTargetBoundsInScreen();
200 gfx::Rect selector_item_bounds = 220 gfx::Rect selector_item_bounds =
201 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio( 221 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio(
202 screen_bounds, target_bounds); 222 screen_bounds, target_bounds);
203 gfx::Transform transform = 223 gfx::Transform transform =
204 ScopedTransformOverviewWindow::GetTransformForRect(screen_bounds, 224 ScopedTransformOverviewWindow::GetTransformForRect(screen_bounds,
205 selector_item_bounds); 225 selector_item_bounds);
206 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; 226 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings;
207 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); 227 transform_window_.BeginScopedAnimation(animation_type, &animation_settings);
208 transform_window_.SetTransform(root_window_, transform); 228 transform_window_.SetTransform(root_window_, transform);
209 transform_window_.set_overview_transform(transform); 229 transform_window_.set_overview_transform(transform);
210 } 230 }
211 231
212 void WindowSelectorItem::SetOpacity(float opacity) { 232 void WindowSelectorItem::SetOpacity(float opacity) {
213 overview_window_button_->SetOpacity(opacity); 233 window_label_->SetOpacity(opacity);
214 close_button_widget_.GetNativeWindow()->layer()->SetOpacity(opacity); 234 close_button_widget_.GetNativeWindow()->layer()->SetOpacity(opacity);
215 235
216 transform_window_.SetOpacity(opacity); 236 transform_window_.SetOpacity(opacity);
217 } 237 }
218 238
239 void WindowSelectorItem::UpdateWindowLabel(
240 const gfx::Rect& window_bounds,
241 OverviewAnimationType animation_type) {
242 // If the root window has changed, force the window label to be recreated
243 // and faded in on the new root window.
244 DCHECK(!window_label_ ||
245 window_label_->GetNativeWindow()->GetRootWindow() == root_window_);
246
247 if (!window_label_->IsVisible()) {
248 window_label_->Show();
249 ScopedOverviewAnimationSettings::SetupFadeInAfterLayout(
250 window_label_->GetNativeWindow());
251 }
252
253 gfx::Rect converted_bounds =
254 ScreenUtil::ConvertRectFromScreen(root_window_, window_bounds);
255 gfx::Rect label_bounds(converted_bounds.x(), converted_bounds.y(),
256 converted_bounds.width(), converted_bounds.height());
257 window_label_button_view_->SetBorder(views::Border::CreateEmptyBorder(
258 label_bounds.height() - kVerticalLabelPadding, 0, 0, 0));
259 ScopedOverviewAnimationSettings animation_settings(
260 animation_type, window_label_->GetNativeWindow());
261
262 window_label_->GetNativeWindow()->SetBounds(label_bounds);
263 }
264
265 void WindowSelectorItem::CreateWindowLabel(const base::string16& title) {
266 window_label_.reset(new views::Widget);
267 views::Widget::InitParams params;
268 params.type = views::Widget::InitParams::TYPE_POPUP;
269 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
270 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
271 params.parent =
272 Shell::GetContainer(root_window_, kShellWindowId_OverlayContainer);
273 params.visible_on_all_workspaces = true;
274 window_label_->set_focus_on_creation(false);
275 window_label_->Init(params);
276 window_label_button_view_ = new views::LabelButton(this, title);
277 window_label_button_view_->SetTextColor(views::LabelButton::STATE_NORMAL,
278 kLabelColor);
279 window_label_button_view_->SetTextColor(views::LabelButton::STATE_HOVERED,
280 kLabelColor);
281 window_label_button_view_->SetTextColor(views::LabelButton::STATE_PRESSED,
282 kLabelColor);
283 window_label_button_view_->set_animate_on_state_change(false);
284 window_label_button_view_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
285 window_label_button_view_->SetTextShadows(gfx::ShadowValues(
286 1, gfx::ShadowValue(gfx::Point(0, kVerticalShadowOffset), kShadowBlur,
287 kLabelShadow)));
288 window_label_button_view_->set_ignore_vertical_overlap(false);
msw 2015/02/03 23:50:19 Would you mind posting a screenshot of what this l
Nina 2015/02/04 16:20:10 Please see screenshots attached to https://crbug.c
289 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
290 window_label_button_view_->SetFontList(
291 bundle.GetFontList(ui::ResourceBundle::BoldFont));
292 window_label_->SetContentsView(window_label_button_view_);
293 }
294
219 void WindowSelectorItem::UpdateCloseButtonLayout( 295 void WindowSelectorItem::UpdateCloseButtonLayout(
220 OverviewAnimationType animation_type) { 296 OverviewAnimationType animation_type) {
221 if (!close_button_->visible()) { 297 if (!close_button_->visible()) {
222 close_button_->SetVisible(true); 298 close_button_->SetVisible(true);
223 ScopedOverviewAnimationSettings::SetupFadeInAfterLayout( 299 ScopedOverviewAnimationSettings::SetupFadeInAfterLayout(
224 close_button_widget_.GetNativeWindow()); 300 close_button_widget_.GetNativeWindow());
225 } 301 }
226 ScopedOverviewAnimationSettings animation_settings(animation_type, 302 ScopedOverviewAnimationSettings animation_settings(animation_type,
227 close_button_widget_.GetNativeWindow()); 303 close_button_widget_.GetNativeWindow());
228 304
229 gfx::Rect transformed_window_bounds = ScreenUtil::ConvertRectFromScreen( 305 gfx::Rect transformed_window_bounds = ScreenUtil::ConvertRectFromScreen(
230 close_button_widget_.GetNativeWindow()->GetRootWindow(), 306 close_button_widget_.GetNativeWindow()->GetRootWindow(),
231 GetTransformedBounds(GetWindow())); 307 GetTransformedBounds(GetWindow()));
232 308
233 gfx::Transform close_button_transform; 309 gfx::Transform close_button_transform;
234 close_button_transform.Translate(transformed_window_bounds.right(), 310 close_button_transform.Translate(transformed_window_bounds.right(),
235 transformed_window_bounds.y()); 311 transformed_window_bounds.y());
236 close_button_widget_.GetNativeWindow()->SetTransform( 312 close_button_widget_.GetNativeWindow()->SetTransform(
237 close_button_transform); 313 close_button_transform);
238 } 314 }
239 315
240 void WindowSelectorItem::UpdateCloseButtonAccessibilityName() { 316 void WindowSelectorItem::UpdateCloseButtonAccessibilityName() {
241 close_button_->SetAccessibleName(l10n_util::GetStringFUTF16( 317 close_button_->SetAccessibleName(l10n_util::GetStringFUTF16(
242 IDS_ASH_OVERVIEW_CLOSE_ITEM_BUTTON_ACCESSIBLE_NAME, 318 IDS_ASH_OVERVIEW_CLOSE_ITEM_BUTTON_ACCESSIBLE_NAME,
243 GetWindow()->title())); 319 GetWindow()->title()));
244 } 320 }
245 321
246 } // namespace ash 322 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698