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