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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 89 |
90 void Launcher::DelegateView::Layout() { | 90 void Launcher::DelegateView::Layout() { |
91 if (child_count() == 0) | 91 if (child_count() == 0) |
92 return; | 92 return; |
93 child_at(0)->SetBounds(0, 0, std::max(0, width() - status_width_), height()); | 93 child_at(0)->SetBounds(0, 0, std::max(0, width() - status_width_), height()); |
94 } | 94 } |
95 | 95 |
96 Launcher::Launcher(aura::Window* window_container) | 96 Launcher::Launcher(aura::Window* window_container) |
97 : widget_(NULL), | 97 : widget_(NULL), |
98 window_container_(window_container), | 98 window_container_(window_container), |
99 delegate_view_(NULL) { | 99 delegate_view_(NULL), |
| 100 launcher_view_(NULL) { |
100 model_.reset(new LauncherModel); | 101 model_.reset(new LauncherModel); |
101 if (Shell::GetInstance()->delegate()) { | 102 if (Shell::GetInstance()->delegate()) { |
102 delegate_.reset( | 103 delegate_.reset( |
103 Shell::GetInstance()->delegate()->CreateLauncherDelegate(model_.get())); | 104 Shell::GetInstance()->delegate()->CreateLauncherDelegate(model_.get())); |
104 } | 105 } |
105 | 106 |
106 widget_.reset(new views::Widget); | 107 widget_.reset(new views::Widget); |
107 views::Widget::InitParams params( | 108 views::Widget::InitParams params( |
108 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 109 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
109 params.create_texture_for_layer = true; | 110 params.create_texture_for_layer = true; |
110 params.transparent = true; | 111 params.transparent = true; |
111 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 112 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
112 params.parent = Shell::GetInstance()->GetContainer( | 113 params.parent = Shell::GetInstance()->GetContainer( |
113 ash::internal::kShellWindowId_LauncherContainer); | 114 ash::internal::kShellWindowId_LauncherContainer); |
114 internal::LauncherView* launcher_view = | 115 launcher_view_ = new internal::LauncherView(model_.get(), delegate_.get()); |
115 new internal::LauncherView(model_.get(), delegate_.get()); | 116 launcher_view_->Init(); |
116 launcher_view->Init(); | |
117 delegate_view_ = new DelegateView; | 117 delegate_view_ = new DelegateView; |
118 delegate_view_->AddChildView(launcher_view); | 118 delegate_view_->AddChildView(launcher_view_); |
119 params.delegate = delegate_view_; | 119 params.delegate = delegate_view_; |
120 widget_->Init(params); | 120 widget_->Init(params); |
121 widget_->GetNativeWindow()->SetName("LauncherWindow"); | 121 widget_->GetNativeWindow()->SetName("LauncherWindow"); |
122 gfx::Size pref = static_cast<views::View*>(launcher_view)->GetPreferredSize(); | 122 gfx::Size pref = |
| 123 static_cast<views::View*>(launcher_view_)->GetPreferredSize(); |
123 widget_->SetBounds(gfx::Rect(0, 0, pref.width(), pref.height())); | 124 widget_->SetBounds(gfx::Rect(0, 0, pref.width(), pref.height())); |
124 // The launcher should not take focus when it is initially shown. | 125 // The launcher should not take focus when it is initially shown. |
125 widget_->set_focus_on_creation(false); | 126 widget_->set_focus_on_creation(false); |
126 widget_->SetContentsView(delegate_view_); | 127 widget_->SetContentsView(delegate_view_); |
127 widget_->Show(); | 128 widget_->Show(); |
128 widget_->GetNativeView()->SetName("LauncherView"); | 129 widget_->GetNativeView()->SetName("LauncherView"); |
129 } | 130 } |
130 | 131 |
131 Launcher::~Launcher() { | 132 Launcher::~Launcher() { |
132 } | 133 } |
133 | 134 |
134 void Launcher::SetStatusWidth(int width) { | 135 void Launcher::SetStatusWidth(int width) { |
135 delegate_view_->SetStatusWidth(width); | 136 delegate_view_->SetStatusWidth(width); |
136 } | 137 } |
137 | 138 |
138 int Launcher::GetStatusWidth() { | 139 int Launcher::GetStatusWidth() { |
139 return delegate_view_->status_width(); | 140 return delegate_view_->status_width(); |
140 } | 141 } |
141 | 142 |
| 143 internal::LauncherView* Launcher::GetLauncherViewForTest() { |
| 144 return static_cast<internal::LauncherView*>( |
| 145 widget_->GetContentsView()->child_at(0)); |
| 146 } |
142 } // namespace ash | 147 } // namespace ash |
OLD | NEW |