OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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/screen_util.h" | |
6 #include "ash/shell.h" | |
7 #include "ash/shell_window_ids.h" | |
8 #include "ash/wm/overview/overview_animation_type.h" | |
9 #include "ash/wm/overview/overview_window_button.h" | |
10 #include "ash/wm/overview/overview_window_targeter.h" | |
11 #include "ash/wm/overview/scoped_overview_animation_settings.h" | |
12 #include "ash/wm/window_state.h" | |
13 #include "ui/aura/scoped_window_targeter.h" | |
14 #include "ui/aura/window.h" | |
15 #include "ui/base/resource/resource_bundle.h" | |
16 #include "ui/views/border.h" | |
17 #include "ui/views/controls/button/label_button.h" | |
18 #include "ui/views/widget/widget.h" | |
19 | |
20 namespace ash { | |
21 | |
22 namespace { | |
23 | |
24 // Foreground label color. | |
25 static const SkColor kLabelColor = SK_ColorWHITE; | |
26 | |
27 // Label shadow color. | |
28 static const SkColor kLabelShadow = 0xB0000000; | |
29 | |
30 // Solid shadow length from the label | |
31 static const int kVerticalShadowOffset = 1; | |
32 | |
33 // Amount of blur applied to the label shadow | |
34 static const int kShadowBlur = 10; | |
flackr
2015/01/23 19:31:55
nit: newline before "} // namespace"
Nina
2015/01/23 20:35:54
Done.
| |
35 } // namespace | |
36 | |
37 // LabelButton shown under each of the windows. | |
38 class OverviewWindowButton::OverviewButtonView : public views::LabelButton { | |
39 public: | |
40 OverviewButtonView(views::ButtonListener* listener, | |
41 const base::string16& text) | |
42 : views::LabelButton(listener, text), | |
43 selector_item_bounds_(gfx::Rect()) {} | |
44 | |
45 ~OverviewButtonView() override {} | |
46 | |
47 // Updates the |selector_item_bounds_|, converting them to our coordinates. | |
48 void SetSelectorItemBounds(const gfx::Rect& selector_item_bounds) { | |
49 selector_item_bounds_ = ScreenUtil::ConvertRectFromScreen( | |
50 GetWidget()->GetNativeWindow()->GetRootWindow(), selector_item_bounds); | |
51 gfx::Point origin = selector_item_bounds_.origin(); | |
52 gfx::Rect target_bounds = GetWidget()->GetNativeWindow()->GetTargetBounds(); | |
53 origin.Offset(-target_bounds.x(), -target_bounds.y()); | |
54 selector_item_bounds_.set_origin(origin); | |
55 } | |
56 | |
57 // views::View: | |
58 void OnMouseReleased(const ui::MouseEvent& event) override { | |
59 if (!selector_item_bounds_.Contains(event.location())) | |
60 return; | |
61 | |
62 NotifyClick(event); | |
63 } | |
64 | |
65 private: | |
66 // Bounds to check if a mouse release occurred outside the window item. | |
67 gfx::Rect selector_item_bounds_; | |
68 | |
69 DISALLOW_COPY_AND_ASSIGN(OverviewButtonView); | |
70 }; | |
71 | |
72 OverviewWindowButton::OverviewWindowButton(aura::Window* target) | |
73 : target_(target), window_label_(new views::Widget) { | |
74 views::Widget::InitParams params; | |
75 params.type = views::Widget::InitParams::TYPE_POPUP; | |
76 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
77 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | |
78 params.parent = Shell::GetContainer(target_->GetRootWindow(), | |
79 kShellWindowId_OverlayContainer); | |
80 params.visible_on_all_workspaces = true; | |
81 window_label_->set_focus_on_creation(false); | |
82 window_label_->Init(params); | |
83 window_label_button_view_ = new OverviewButtonView(this, target_->title()); | |
84 window_label_button_view_->SetTextColor(views::LabelButton::STATE_NORMAL, | |
85 kLabelColor); | |
86 window_label_button_view_->SetTextColor(views::LabelButton::STATE_HOVERED, | |
87 kLabelColor); | |
88 window_label_button_view_->SetTextColor(views::LabelButton::STATE_PRESSED, | |
89 kLabelColor); | |
90 window_label_button_view_->set_animate_on_state_change(false); | |
91 window_label_button_view_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | |
92 window_label_button_view_->SetBorder(views::Border::NullBorder()); | |
93 window_label_button_view_->SetTextShadows(gfx::ShadowValues( | |
94 1, gfx::ShadowValue(gfx::Point(0, kVerticalShadowOffset), kShadowBlur, | |
95 kLabelShadow))); | |
96 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
97 window_label_button_view_->SetFontList( | |
98 bundle.GetFontList(ui::ResourceBundle::BoldFont)); | |
99 window_label_->SetContentsView(window_label_button_view_); | |
100 | |
101 overview_window_targeter_ = | |
102 new OverviewWindowTargeter(window_label_->GetNativeWindow()); | |
103 scoped_window_targeter_.reset(new aura::ScopedWindowTargeter( | |
104 target, scoped_ptr<OverviewWindowTargeter>(overview_window_targeter_))); | |
105 } | |
106 | |
107 OverviewWindowButton::~OverviewWindowButton() { | |
108 } | |
109 | |
110 void OverviewWindowButton::SetBounds( | |
111 const gfx::Rect& bounds, | |
112 const OverviewAnimationType& animation_type) { | |
113 if (!window_label_->IsVisible()) { | |
114 window_label_->Show(); | |
115 ScopedOverviewAnimationSettings::SetupFadeInAfterLayout( | |
116 window_label_->GetNativeWindow()); | |
117 } | |
118 gfx::Rect converted_bounds = | |
119 ScreenUtil::ConvertRectFromScreen(target_->GetRootWindow(), bounds); | |
120 gfx::Rect label_bounds(converted_bounds.x(), converted_bounds.bottom(), | |
121 converted_bounds.width(), 0); | |
122 label_bounds.set_height( | |
123 window_label_->GetContentsView()->GetPreferredSize().height()); | |
124 label_bounds.set_y( | |
125 label_bounds.y() - | |
126 window_label_->GetContentsView()->GetPreferredSize().height()); | |
127 | |
128 ScopedOverviewAnimationSettings animation_settings( | |
129 animation_type, window_label_->GetNativeWindow()); | |
130 | |
131 window_label_->GetNativeWindow()->SetBounds(label_bounds); | |
132 window_label_button_view_->SetSelectorItemBounds(bounds); | |
133 overview_window_targeter_->set_bounds( | |
134 ScreenUtil::ConvertRectFromScreen(target_->GetRootWindow(), bounds)); | |
135 } | |
136 | |
137 void OverviewWindowButton::SendFocusAlert() const { | |
138 window_label_button_view_->NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, true); | |
139 } | |
140 | |
141 void OverviewWindowButton::SetLabelText(const base::string16& title) { | |
142 window_label_button_view_->SetText(title); | |
143 } | |
144 | |
145 void OverviewWindowButton::SetOpacity(float opacity) { | |
146 window_label_->GetNativeWindow()->layer()->SetOpacity(opacity); | |
147 } | |
148 | |
149 void OverviewWindowButton::ButtonPressed(views::Button* sender, | |
150 const ui::Event& event) { | |
151 wm::GetWindowState(target_)->Activate(); | |
152 } | |
153 | |
154 } // namespace ash | |
OLD | NEW |