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

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

Issue 231643002: Added labels under the windows in OverviewMode displaying their current name. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed nits, added transparency Created 6 years, 8 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
7 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h"
9 #include "ash/wm/overview/scoped_transform_overview_window.h"
6 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "third_party/skia/include/core/SkColor.h"
7 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/compositor/scoped_layer_animation_settings.h"
16 #include "ui/views/controls/label.h"
17 #include "ui/views/layout/box_layout.h"
18 #include "ui/views/widget/widget.h"
8 19
9 namespace ash { 20 namespace ash {
10 21
22 // Foreground label color.
23 static const SkColor kLabelColor = SK_ColorWHITE;
24
25 // Background label color.
26 static const SkColor kLabelBackground = SK_ColorTRANSPARENT;
27
28 // Label shadow color.
29 static const SkColor kLabelShadow = 0x88000000;
30
31 // Vertical padding for the label, both over and beneath it.
32 static const int kVerticalLabelPadding = 20;
33
34 // Label height, ie. distance from the border of the window to the label bottom.
flackr 2014/04/14 20:31:18 nit: i.e.
Nina 2014/04/15 15:15:03 Done.
35 static const int kLabelHeight = 20;
36
37 views::Widget* CreateWindowLabel(aura::Window* root_window,
38 const base::string16 title) {
39 views::Widget* widget = new views::Widget;
40 views::Widget::InitParams params;
41 params.type = views::Widget::InitParams::TYPE_POPUP;
42 params.can_activate = false;
43 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
44 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
45 params.parent =
46 Shell::GetContainer(root_window, ash::kShellWindowId_OverlayContainer);
47 params.accept_events = false;
48 widget->set_focus_on_creation(false);
49 widget->Init(params);
50 views::Label* label = new views::Label;
51 label->SetEnabledColor(kLabelColor);
52 label->SetBackgroundColor(kLabelBackground);
53 label->SetShadowColors(kLabelShadow, kLabelShadow);
54 label->SetShadowOffset(1, 1);
55 label->SetShadowBlur(2);
56 label->SetMirrorShadow(true);
57 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
58 label->SetFontList(bundle.GetFontList(ui::ResourceBundle::BoldFont));
59 label->SetText(title);
60 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kVertical,
61 0,
62 kVerticalLabelPadding,
63 0);
64 label->SetLayoutManager(layout);
65 widget->SetContentsView(label);
66 widget->Show();
67 return widget;
68 }
69
11 WindowSelectorItem::WindowSelectorItem() 70 WindowSelectorItem::WindowSelectorItem()
12 : root_window_(NULL), 71 : root_window_(NULL),
13 in_bounds_update_(false) { 72 in_bounds_update_(false) {
14 } 73 }
15 74
16 WindowSelectorItem::~WindowSelectorItem() { 75 WindowSelectorItem::~WindowSelectorItem() {
17 } 76 }
18 77
19 void WindowSelectorItem::SetBounds(aura::Window* root_window, 78 void WindowSelectorItem::SetBounds(aura::Window* root_window,
20 const gfx::Rect& target_bounds) { 79 const gfx::Rect& target_bounds) {
21 if (in_bounds_update_) 80 if (in_bounds_update_)
22 return; 81 return;
23 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true); 82 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true);
24 root_window_ = root_window; 83 root_window_ = root_window;
25 target_bounds_ = target_bounds; 84 target_bounds_ = target_bounds;
26 SetItemBounds(root_window, target_bounds, true); 85 SetItemBounds(root_window, target_bounds, true);
86 UpdateWindowLabels(target_bounds);
27 } 87 }
28 88
29 void WindowSelectorItem::RecomputeWindowTransforms() { 89 void WindowSelectorItem::RecomputeWindowTransforms() {
30 if (in_bounds_update_ || target_bounds_.IsEmpty()) 90 if (in_bounds_update_ || target_bounds_.IsEmpty())
31 return; 91 return;
32 DCHECK(root_window_); 92 DCHECK(root_window_);
33 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true); 93 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true);
34 SetItemBounds(root_window_, target_bounds_, false); 94 SetItemBounds(root_window_, target_bounds_, false);
35 } 95 }
36 96
97 void WindowSelectorItem::UpdateWindowLabels(const gfx::Rect& window_bounds) {
98 aura::Window* root_window = GetRootWindow();
99
100 gfx::Rect label_bounds(window_bounds.x(),
101 window_bounds.y() + window_bounds.height(),
102 window_bounds.width(),
103 kLabelHeight);
104
105 // If the root window has changed, force the window label to be recreated
106 // and faded in on the new root window.
107 if (window_label_ &&
108 window_label_->GetNativeWindow()->GetRootWindow() != root_window) {
109 window_label_.reset();
110 }
111
112 if (!window_label_) {
113 window_label_.reset(CreateWindowLabel(GetRootWindow(), GetLabelName()));
114 window_label_->GetNativeWindow()->SetBounds(label_bounds);
115 ui::Layer* layer = window_label_->GetNativeWindow()->layer();
116
117 layer->SetOpacity(0);
118 layer->GetAnimator()->StopAnimating();
119
120 layer->GetAnimator()->SchedulePauseForProperties(
121 base::TimeDelta::FromMilliseconds(
122 ScopedTransformOverviewWindow::kTransitionMilliseconds),
123 ui::LayerAnimationElement::OPACITY);
124
125 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator());
126 settings.SetPreemptionStrategy(
127 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
128 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
129 ScopedTransformOverviewWindow::kFadeInMilliseconds));
130 layer->SetOpacity(1);
131 } else {
132 ui::ScopedLayerAnimationSettings settings(
133 window_label_->GetNativeWindow()->layer()->GetAnimator());
134 settings.SetPreemptionStrategy(
135 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
136 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
137 ScopedTransformOverviewWindow::kTransitionMilliseconds));
138 window_label_->GetNativeWindow()->SetBounds(label_bounds);
139 }
140
141 }
142
37 } // namespace ash 143 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698