OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/launcher/launcher.h" | 5 #include "ash/launcher/launcher.h" |
6 | 6 |
7 #include "ash/focus_cycler.h" | 7 #include "ash/focus_cycler.h" |
8 #include "ash/launcher/launcher_delegate.h" | 8 #include "ash/launcher/launcher_delegate.h" |
9 #include "ash/launcher/launcher_model.h" | 9 #include "ash/launcher/launcher_model.h" |
10 #include "ash/launcher/launcher_view.h" | 10 #include "ash/launcher/launcher_view.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 } | 30 } |
31 | 31 |
32 // The contents view of the Widget. This view contains LauncherView and | 32 // The contents view of the Widget. This view contains LauncherView and |
33 // sizes it to the width of the widget minus the size of the status area. | 33 // sizes it to the width of the widget minus the size of the status area. |
34 class Launcher::DelegateView : public views::WidgetDelegate, | 34 class Launcher::DelegateView : public views::WidgetDelegate, |
35 public views::AccessiblePaneView{ | 35 public views::AccessiblePaneView{ |
36 public: | 36 public: |
37 explicit DelegateView(Launcher* launcher); | 37 explicit DelegateView(Launcher* launcher); |
38 virtual ~DelegateView(); | 38 virtual ~DelegateView(); |
39 | 39 |
40 void SetStatusWidth(int width); | |
41 int status_width() const { return status_width_; } | |
42 | |
43 void set_focus_cycler(internal::FocusCycler* focus_cycler) { | 40 void set_focus_cycler(internal::FocusCycler* focus_cycler) { |
44 focus_cycler_ = focus_cycler; | 41 focus_cycler_ = focus_cycler; |
45 } | 42 } |
46 internal::FocusCycler* focus_cycler() { | 43 internal::FocusCycler* focus_cycler() { |
47 return focus_cycler_; | 44 return focus_cycler_; |
48 } | 45 } |
49 | 46 |
50 // views::View overrides | 47 // views::View overrides |
51 virtual gfx::Size GetPreferredSize() OVERRIDE; | 48 virtual gfx::Size GetPreferredSize() OVERRIDE; |
52 virtual void Layout() OVERRIDE; | 49 virtual void Layout() OVERRIDE; |
53 | 50 |
54 // views::WidgetDelegateView overrides: | 51 // views::WidgetDelegateView overrides: |
55 virtual views::Widget* GetWidget() OVERRIDE { | 52 virtual views::Widget* GetWidget() OVERRIDE { |
56 return View::GetWidget(); | 53 return View::GetWidget(); |
57 } | 54 } |
58 virtual const views::Widget* GetWidget() const OVERRIDE { | 55 virtual const views::Widget* GetWidget() const OVERRIDE { |
59 return View::GetWidget(); | 56 return View::GetWidget(); |
60 } | 57 } |
61 virtual bool CanActivate() const OVERRIDE { | 58 virtual bool CanActivate() const OVERRIDE { |
62 // We don't want mouse clicks to activate us, but we need to allow | 59 // We don't want mouse clicks to activate us, but we need to allow |
63 // activation when the user is using the keyboard (FocusCycler). | 60 // activation when the user is using the keyboard (FocusCycler). |
64 return focus_cycler_ && focus_cycler_->widget_activating() == GetWidget(); | 61 return focus_cycler_ && focus_cycler_->widget_activating() == GetWidget(); |
65 } | 62 } |
66 | 63 |
67 private: | 64 private: |
68 Launcher* launcher_; | 65 Launcher* launcher_; |
69 | |
70 // Width of the status area. | |
71 int status_width_; | |
72 | |
73 internal::FocusCycler* focus_cycler_; | 66 internal::FocusCycler* focus_cycler_; |
74 | 67 |
75 DISALLOW_COPY_AND_ASSIGN(DelegateView); | 68 DISALLOW_COPY_AND_ASSIGN(DelegateView); |
76 }; | 69 }; |
77 | 70 |
78 Launcher::DelegateView::DelegateView(Launcher* launcher) | 71 Launcher::DelegateView::DelegateView(Launcher* launcher) |
79 : launcher_(launcher), | 72 : launcher_(launcher), |
80 status_width_(0), | |
81 focus_cycler_(NULL) { | 73 focus_cycler_(NULL) { |
82 } | 74 } |
83 | 75 |
84 Launcher::DelegateView::~DelegateView() { | 76 Launcher::DelegateView::~DelegateView() { |
85 } | 77 } |
86 | 78 |
87 void Launcher::DelegateView::SetStatusWidth(int width) { | |
88 if (status_width_ == width) | |
89 return; | |
90 | |
91 status_width_ = width; | |
92 Layout(); | |
93 } | |
94 | |
95 gfx::Size Launcher::DelegateView::GetPreferredSize() { | 79 gfx::Size Launcher::DelegateView::GetPreferredSize() { |
96 return child_count() > 0 ? child_at(0)->GetPreferredSize() : gfx::Size(); | 80 return child_count() > 0 ? child_at(0)->GetPreferredSize() : gfx::Size(); |
97 } | 81 } |
98 | 82 |
99 void Launcher::DelegateView::Layout() { | 83 void Launcher::DelegateView::Layout() { |
100 if (child_count() == 0) | 84 if (child_count() == 0) |
101 return; | 85 return; |
102 child_at(0)->SetBounds(0, 0, std::max(0, width() - status_width_), height()); | 86 if (launcher_->alignment_ == SHELF_ALIGNMENT_BOTTOM) { |
| 87 int w = std::max(0, width() - launcher_->status_size_.width()); |
| 88 child_at(0)->SetBounds(0, 0, w, height()); |
| 89 } else { |
| 90 int h = std::max(0, height() - launcher_->status_size_.height()); |
| 91 child_at(0)->SetBounds(0, 0, width(), h); |
| 92 } |
103 } | 93 } |
104 | 94 |
105 // Launcher -------------------------------------------------------------------- | 95 // Launcher -------------------------------------------------------------------- |
106 | 96 |
107 Launcher::Launcher(aura::Window* window_container) | 97 Launcher::Launcher(aura::Window* window_container) |
108 : widget_(NULL), | 98 : widget_(NULL), |
109 window_container_(window_container), | 99 window_container_(window_container), |
110 delegate_view_(NULL), | 100 delegate_view_(NULL), |
111 launcher_view_(NULL), | 101 launcher_view_(NULL), |
| 102 alignment_(SHELF_ALIGNMENT_BOTTOM), |
112 ALLOW_THIS_IN_INITIALIZER_LIST( | 103 ALLOW_THIS_IN_INITIALIZER_LIST( |
113 background_animator_(this, 0, kBackgroundAlpha)) { | 104 background_animator_(this, 0, kBackgroundAlpha)) { |
114 model_.reset(new LauncherModel); | 105 model_.reset(new LauncherModel); |
115 if (Shell::GetInstance()->delegate()) { | 106 if (Shell::GetInstance()->delegate()) { |
116 delegate_.reset( | 107 delegate_.reset( |
117 Shell::GetInstance()->delegate()->CreateLauncherDelegate(model_.get())); | 108 Shell::GetInstance()->delegate()->CreateLauncherDelegate(model_.get())); |
118 } | 109 } |
119 | 110 |
120 widget_.reset(new views::Widget); | 111 widget_.reset(new views::Widget); |
121 views::Widget::InitParams params( | 112 views::Widget::InitParams params( |
122 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 113 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
123 // The launcher only ever draws a solid color. | 114 // The launcher only ever draws a solid color. |
124 params.layer_type = ui::LAYER_SOLID_COLOR; | 115 params.layer_type = ui::LAYER_SOLID_COLOR; |
125 params.transparent = true; | 116 params.transparent = true; |
126 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 117 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
127 params.parent = Shell::GetInstance()->GetContainer( | 118 params.parent = Shell::GetInstance()->GetContainer( |
128 ash::internal::kShellWindowId_LauncherContainer); | 119 ash::internal::kShellWindowId_LauncherContainer); |
129 launcher_view_ = new internal::LauncherView(model_.get(), delegate_.get()); | 120 launcher_view_ = new internal::LauncherView(model_.get(), delegate_.get()); |
130 launcher_view_->Init(); | 121 launcher_view_->Init(); |
131 delegate_view_ = new DelegateView(this); | 122 delegate_view_ = new DelegateView(this); |
132 delegate_view_->AddChildView(launcher_view_); | 123 delegate_view_->AddChildView(launcher_view_); |
133 params.delegate = delegate_view_; | 124 params.delegate = delegate_view_; |
134 widget_->Init(params); | 125 widget_->Init(params); |
135 widget_->GetNativeWindow()->SetName("LauncherWindow"); | 126 widget_->GetNativeWindow()->SetName("LauncherWindow"); |
136 gfx::Size pref = | 127 gfx::Size pref = |
137 static_cast<views::View*>(launcher_view_)->GetPreferredSize(); | 128 static_cast<views::View*>(launcher_view_)->GetPreferredSize(); |
138 widget_->SetBounds(gfx::Rect(0, 0, pref.width(), pref.height())); | 129 widget_->SetBounds(gfx::Rect(pref)); |
139 // The launcher should not take focus when it is initially shown. | 130 // The launcher should not take focus when it is initially shown. |
140 widget_->set_focus_on_creation(false); | 131 widget_->set_focus_on_creation(false); |
141 widget_->SetContentsView(delegate_view_); | 132 widget_->SetContentsView(delegate_view_); |
142 widget_->Show(); | 133 widget_->Show(); |
143 widget_->GetNativeView()->SetName("LauncherView"); | 134 widget_->GetNativeView()->SetName("LauncherView"); |
144 } | 135 } |
145 | 136 |
146 Launcher::~Launcher() { | 137 Launcher::~Launcher() { |
147 } | 138 } |
148 | 139 |
149 void Launcher::SetFocusCycler(internal::FocusCycler* focus_cycler) { | 140 void Launcher::SetFocusCycler(internal::FocusCycler* focus_cycler) { |
150 delegate_view_->set_focus_cycler(focus_cycler); | 141 delegate_view_->set_focus_cycler(focus_cycler); |
151 focus_cycler->AddWidget(widget_.get()); | 142 focus_cycler->AddWidget(widget_.get()); |
152 } | 143 } |
153 | 144 |
154 internal::FocusCycler* Launcher::GetFocusCycler() { | 145 internal::FocusCycler* Launcher::GetFocusCycler() { |
155 return delegate_view_->focus_cycler(); | 146 return delegate_view_->focus_cycler(); |
156 } | 147 } |
157 | 148 |
| 149 void Launcher::SetAlignment(ShelfAlignment alignment) { |
| 150 alignment_ = alignment; |
| 151 launcher_view_->SetAlignment(alignment); |
| 152 // ShelfLayoutManager will resize the launcher. |
| 153 } |
| 154 |
158 void Launcher::SetPaintsBackground( | 155 void Launcher::SetPaintsBackground( |
159 bool value, | 156 bool value, |
160 internal::BackgroundAnimator::ChangeType change_type) { | 157 internal::BackgroundAnimator::ChangeType change_type) { |
161 background_animator_.SetPaintsBackground(value, change_type); | 158 background_animator_.SetPaintsBackground(value, change_type); |
162 } | 159 } |
163 | 160 |
164 void Launcher::SetStatusWidth(int width) { | 161 void Launcher::SetStatusSize(const gfx::Size& size) { |
165 delegate_view_->SetStatusWidth(width); | 162 if (status_size_ == size) |
166 } | 163 return; |
167 | 164 |
168 int Launcher::GetStatusWidth() { | 165 status_size_ = size; |
169 return delegate_view_->status_width(); | 166 delegate_view_->Layout(); |
170 } | 167 } |
171 | 168 |
172 gfx::Rect Launcher::GetScreenBoundsOfItemIconForWindow(aura::Window* window) { | 169 gfx::Rect Launcher::GetScreenBoundsOfItemIconForWindow(aura::Window* window) { |
173 if (!delegate_.get()) | 170 if (!delegate_.get()) |
174 return gfx::Rect(); | 171 return gfx::Rect(); |
175 | 172 |
176 LauncherID id = delegate_->GetIDByWindow(window); | 173 LauncherID id = delegate_->GetIDByWindow(window); |
177 gfx::Rect bounds(launcher_view_->GetIdealBoundsOfItemIcon(id)); | 174 gfx::Rect bounds(launcher_view_->GetIdealBoundsOfItemIcon(id)); |
178 if (bounds.IsEmpty()) | 175 if (bounds.IsEmpty()) |
179 return bounds; | 176 return bounds; |
(...skipping 25 matching lines...) Expand all Loading... |
205 internal::LauncherView* Launcher::GetLauncherViewForTest() { | 202 internal::LauncherView* Launcher::GetLauncherViewForTest() { |
206 return launcher_view_; | 203 return launcher_view_; |
207 } | 204 } |
208 | 205 |
209 void Launcher::UpdateBackground(int alpha) { | 206 void Launcher::UpdateBackground(int alpha) { |
210 ui::Layer* layer = widget_->GetNativeView()->layer(); | 207 ui::Layer* layer = widget_->GetNativeView()->layer(); |
211 layer->SetColor(SkColorSetARGB(alpha, 0, 0, 0)); | 208 layer->SetColor(SkColorSetARGB(alpha, 0, 0, 0)); |
212 } | 209 } |
213 | 210 |
214 } // namespace ash | 211 } // namespace ash |
OLD | NEW |