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 "ui/app_list/views/app_list_view.h" | 5 #include "ui/app_list/views/app_list_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "ui/app_list/views/app_list_view_observer.h" | 21 #include "ui/app_list/views/app_list_view_observer.h" |
22 #include "ui/app_list/views/apps_container_view.h" | 22 #include "ui/app_list/views/apps_container_view.h" |
23 #include "ui/app_list/views/contents_view.h" | 23 #include "ui/app_list/views/contents_view.h" |
24 #include "ui/app_list/views/search_box_view.h" | 24 #include "ui/app_list/views/search_box_view.h" |
25 #include "ui/app_list/views/signin_view.h" | 25 #include "ui/app_list/views/signin_view.h" |
26 #include "ui/app_list/views/speech_view.h" | 26 #include "ui/app_list/views/speech_view.h" |
27 #include "ui/base/ui_base_switches.h" | 27 #include "ui/base/ui_base_switches.h" |
28 #include "ui/compositor/layer.h" | 28 #include "ui/compositor/layer.h" |
29 #include "ui/compositor/layer_animation_observer.h" | 29 #include "ui/compositor/layer_animation_observer.h" |
30 #include "ui/compositor/scoped_layer_animation_settings.h" | 30 #include "ui/compositor/scoped_layer_animation_settings.h" |
31 #include "ui/gfx/display.h" | |
32 #include "ui/gfx/image/image_skia.h" | 31 #include "ui/gfx/image/image_skia.h" |
33 #include "ui/gfx/insets.h" | 32 #include "ui/gfx/insets.h" |
34 #include "ui/gfx/path.h" | 33 #include "ui/gfx/path.h" |
35 #include "ui/gfx/screen.h" | |
36 #include "ui/gfx/skia_util.h" | 34 #include "ui/gfx/skia_util.h" |
37 #include "ui/views/bubble/bubble_frame_view.h" | 35 #include "ui/views/bubble/bubble_frame_view.h" |
38 #include "ui/views/bubble/bubble_window_targeter.h" | 36 #include "ui/views/bubble/bubble_window_targeter.h" |
39 #include "ui/views/controls/textfield/textfield.h" | 37 #include "ui/views/controls/textfield/textfield.h" |
40 #include "ui/views/layout/fill_layout.h" | 38 #include "ui/views/layout/fill_layout.h" |
41 #include "ui/views/widget/widget.h" | 39 #include "ui/views/widget/widget.h" |
42 | 40 |
43 #if defined(USE_AURA) | 41 #if defined(USE_AURA) |
44 #include "ui/aura/window.h" | 42 #include "ui/aura/window.h" |
45 #include "ui/aura/window_tree_host.h" | 43 #include "ui/aura/window_tree_host.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 }; | 122 }; |
125 | 123 |
126 //////////////////////////////////////////////////////////////////////////////// | 124 //////////////////////////////////////////////////////////////////////////////// |
127 // AppListView: | 125 // AppListView: |
128 | 126 |
129 AppListView::AppListView(AppListViewDelegate* delegate) | 127 AppListView::AppListView(AppListViewDelegate* delegate) |
130 : delegate_(delegate), | 128 : delegate_(delegate), |
131 app_list_main_view_(NULL), | 129 app_list_main_view_(NULL), |
132 signin_view_(NULL), | 130 signin_view_(NULL), |
133 speech_view_(NULL), | 131 speech_view_(NULL), |
134 animation_observer_(new HideViewAnimationObserver()), | 132 animation_observer_(new HideViewAnimationObserver()) { |
135 screen_to_keep_centered_on_(NULL) { | |
136 CHECK(delegate); | 133 CHECK(delegate); |
137 | 134 |
138 delegate_->AddObserver(this); | 135 delegate_->AddObserver(this); |
139 delegate_->GetSpeechUI()->AddObserver(this); | 136 delegate_->GetSpeechUI()->AddObserver(this); |
140 } | 137 } |
141 | 138 |
142 AppListView::~AppListView() { | 139 AppListView::~AppListView() { |
143 delegate_->GetSpeechUI()->RemoveObserver(this); | 140 delegate_->GetSpeechUI()->RemoveObserver(this); |
144 delegate_->RemoveObserver(this); | 141 delegate_->RemoveObserver(this); |
145 animation_observer_.reset(); | 142 animation_observer_.reset(); |
146 // Remove child views first to ensure no remaining dependencies on delegate_. | 143 // Remove child views first to ensure no remaining dependencies on delegate_. |
147 RemoveAllChildViews(true); | 144 RemoveAllChildViews(true); |
148 } | 145 } |
149 | 146 |
150 void AppListView::InitAsBubbleAttachedToAnchor( | 147 void AppListView::InitAsBubbleAttachedToAnchor( |
151 gfx::NativeView parent, | 148 gfx::NativeView parent, |
152 PaginationModel* pagination_model, | 149 PaginationModel* pagination_model, |
153 views::View* anchor, | 150 views::View* anchor, |
154 const gfx::Vector2d& anchor_offset, | 151 const gfx::Vector2d& anchor_offset, |
155 views::BubbleBorder::Arrow arrow, | 152 views::BubbleBorder::Arrow arrow, |
156 bool border_accepts_events) { | 153 bool border_accepts_events) { |
157 SetAnchorView(anchor); | 154 SetAnchorView(anchor); |
158 InitAsBubbleInternal( | 155 InitAsBubbleInternal( |
159 parent, pagination_model, arrow, border_accepts_events, anchor_offset); | 156 parent, pagination_model, arrow, border_accepts_events, anchor_offset); |
160 screen_to_keep_centered_on_ = NULL; | |
161 } | 157 } |
162 | 158 |
163 void AppListView::InitAsBubbleAtFixedLocation( | 159 void AppListView::InitAsBubbleAtFixedLocation( |
164 gfx::NativeView parent, | 160 gfx::NativeView parent, |
165 PaginationModel* pagination_model, | 161 PaginationModel* pagination_model, |
166 const gfx::Point& anchor_point_in_screen, | 162 const gfx::Point& anchor_point_in_screen, |
167 views::BubbleBorder::Arrow arrow, | 163 views::BubbleBorder::Arrow arrow, |
168 bool border_accepts_events) { | 164 bool border_accepts_events) { |
169 SetAnchorView(NULL); | 165 SetAnchorView(NULL); |
170 SetAnchorRect(gfx::Rect(anchor_point_in_screen, gfx::Size())); | 166 SetAnchorRect(gfx::Rect(anchor_point_in_screen, gfx::Size())); |
171 InitAsBubbleInternal( | 167 InitAsBubbleInternal( |
172 parent, pagination_model, arrow, border_accepts_events, gfx::Vector2d()); | 168 parent, pagination_model, arrow, border_accepts_events, gfx::Vector2d()); |
173 screen_to_keep_centered_on_ = NULL; | |
174 } | |
175 | |
176 void AppListView::InitAsBubbleCenteredOnPrimaryDisplay( | |
177 gfx::NativeView parent, | |
178 PaginationModel* pagination_model, | |
179 gfx::Screen* screen_to_keep_centered_on, | |
180 views::BubbleBorder::Arrow arrow, | |
181 bool border_accepts_events) { | |
182 screen_to_keep_centered_on_ = screen_to_keep_centered_on; | |
183 SetAnchorView(NULL); | |
184 SetAnchorRect(gfx::Rect(GetCenterPoint(), gfx::Size())); | |
185 InitAsBubbleInternal( | |
186 parent, pagination_model, arrow, border_accepts_events, gfx::Vector2d()); | |
187 } | 169 } |
188 | 170 |
189 void AppListView::SetBubbleArrow(views::BubbleBorder::Arrow arrow) { | 171 void AppListView::SetBubbleArrow(views::BubbleBorder::Arrow arrow) { |
190 GetBubbleFrameView()->bubble_border()->set_arrow(arrow); | 172 GetBubbleFrameView()->bubble_border()->set_arrow(arrow); |
191 SizeToContents(); // Recalcuates with new border. | 173 SizeToContents(); // Recalcuates with new border. |
192 GetBubbleFrameView()->SchedulePaint(); | 174 GetBubbleFrameView()->SchedulePaint(); |
193 } | 175 } |
194 | 176 |
195 void AppListView::SetAnchorPoint(const gfx::Point& anchor_point) { | 177 void AppListView::SetAnchorPoint(const gfx::Point& anchor_point) { |
196 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size())); | 178 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size())); |
197 } | 179 } |
198 | 180 |
199 void AppListView::SetDragAndDropHostOfCurrentAppList( | 181 void AppListView::SetDragAndDropHostOfCurrentAppList( |
200 ApplicationDragAndDropHost* drag_and_drop_host) { | 182 ApplicationDragAndDropHost* drag_and_drop_host) { |
201 app_list_main_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); | 183 app_list_main_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); |
202 } | 184 } |
203 | 185 |
204 void AppListView::ShowWhenReady() { | 186 void AppListView::ShowWhenReady() { |
205 app_list_main_view_->ShowAppListWhenReady(); | 187 app_list_main_view_->ShowAppListWhenReady(); |
206 } | 188 } |
207 | 189 |
208 void AppListView::Close() { | 190 void AppListView::Close() { |
209 app_list_main_view_->Close(); | 191 app_list_main_view_->Close(); |
210 delegate_->Dismiss(); | 192 delegate_->Dismiss(); |
211 } | 193 } |
212 | 194 |
213 void AppListView::UpdateBounds() { | 195 void AppListView::UpdateBounds() { |
214 if (screen_to_keep_centered_on_) | |
215 SetAnchorRect(gfx::Rect(GetCenterPoint(), gfx::Size())); | |
216 SizeToContents(); | 196 SizeToContents(); |
217 } | 197 } |
218 | 198 |
219 gfx::Size AppListView::GetPreferredSize() { | 199 gfx::Size AppListView::GetPreferredSize() { |
220 return app_list_main_view_->GetPreferredSize(); | 200 return app_list_main_view_->GetPreferredSize(); |
221 } | 201 } |
222 | 202 |
223 void AppListView::Paint(gfx::Canvas* canvas) { | 203 void AppListView::Paint(gfx::Canvas* canvas) { |
224 views::BubbleDelegateView::Paint(canvas); | 204 views::BubbleDelegateView::Paint(canvas); |
225 if (g_next_paint_callback) { | 205 if (g_next_paint_callback) { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 // widget to ensure that any WM_WINDOWPOSCHANGED messages triggered by the | 330 // widget to ensure that any WM_WINDOWPOSCHANGED messages triggered by the |
351 // window manager do not have the SWP_SHOWWINDOW flag set which would cause | 331 // window manager do not have the SWP_SHOWWINDOW flag set which would cause |
352 // the border to be shown. See http://crbug.com/231687 . | 332 // the border to be shown. See http://crbug.com/231687 . |
353 GetWidget()->Hide(); | 333 GetWidget()->Hide(); |
354 #endif | 334 #endif |
355 | 335 |
356 if (delegate_) | 336 if (delegate_) |
357 delegate_->ViewInitialized(); | 337 delegate_->ViewInitialized(); |
358 } | 338 } |
359 | 339 |
360 gfx::Point AppListView::GetCenterPoint() { | |
361 DCHECK(screen_to_keep_centered_on_); | |
362 gfx::Rect bounds = screen_to_keep_centered_on_->GetPrimaryDisplay().bounds(); | |
363 return bounds.CenterPoint(); | |
364 } | |
365 | |
366 void AppListView::OnBeforeBubbleWidgetInit( | 340 void AppListView::OnBeforeBubbleWidgetInit( |
367 views::Widget::InitParams* params, | 341 views::Widget::InitParams* params, |
368 views::Widget* widget) const { | 342 views::Widget* widget) const { |
369 #if defined(USE_AURA) && !defined(OS_CHROMEOS) | 343 #if defined(USE_AURA) && !defined(OS_CHROMEOS) |
370 if (delegate_ && delegate_->ForceNativeDesktop()) | 344 if (delegate_ && delegate_->ForceNativeDesktop()) |
371 params->native_widget = new views::DesktopNativeWidgetAura(widget); | 345 params->native_widget = new views::DesktopNativeWidgetAura(widget); |
372 #endif | 346 #endif |
373 #if defined(OS_WIN) | 347 #if defined(OS_WIN) |
374 // Windows 7 and higher offer pinning to the taskbar, but we need presence | 348 // Windows 7 and higher offer pinning to the taskbar, but we need presence |
375 // on the taskbar for the user to be able to pin us. So, show the window on | 349 // on the taskbar for the user to be able to pin us. So, show the window on |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 #else | 510 #else |
537 speech_view_->SetVisible(recognizing); | 511 speech_view_->SetVisible(recognizing); |
538 app_list_main_view_->SetVisible(!recognizing); | 512 app_list_main_view_->SetVisible(!recognizing); |
539 | 513 |
540 // Needs to schedule paint of AppListView itself, to repaint the background. | 514 // Needs to schedule paint of AppListView itself, to repaint the background. |
541 GetBubbleFrameView()->SchedulePaint(); | 515 GetBubbleFrameView()->SchedulePaint(); |
542 #endif | 516 #endif |
543 } | 517 } |
544 | 518 |
545 } // namespace app_list | 519 } // namespace app_list |
OLD | NEW |