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

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

Powered by Google App Engine
This is Rietveld 408576698