Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: ui/app_list/views/app_list_view.cc

Issue 2934513004: Changed static variable flag to be a bool in the anon namespace. (Closed)
Patch Set: In AppListView: Moved function and variable out of the global scope. In SearchBoxView: Moved variab… Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/macros.h" 10 #include "base/macros.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // The velocity the app list must be dragged in order to transition to the next 68 // The velocity the app list must be dragged in order to transition to the next
69 // state, measured in DIPs/event. 69 // state, measured in DIPs/event.
70 constexpr int kAppListDragVelocityThreshold = 25; 70 constexpr int kAppListDragVelocityThreshold = 25;
71 71
72 // The opacity of the app list background. 72 // The opacity of the app list background.
73 constexpr float kAppListOpacity = 0.8; 73 constexpr float kAppListOpacity = 0.8;
74 74
75 // The vertical position for the appearing animation of the speech UI. 75 // The vertical position for the appearing animation of the speech UI.
76 constexpr float kSpeechUIAppearingPosition = 12; 76 constexpr float kSpeechUIAppearingPosition = 12;
77 77
78 bool IsFullscreenAppListEnabled() {
79 // Cache this value to avoid repeated lookup.
80 static bool cached_value = features::IsFullscreenAppListEnabled();
81 return cached_value;
82 }
83
84 // This view forwards the focus to the search box widget by providing it as a 78 // This view forwards the focus to the search box widget by providing it as a
85 // FocusTraversable when a focus search is provided. 79 // FocusTraversable when a focus search is provided.
86 class SearchBoxFocusHost : public views::View { 80 class SearchBoxFocusHost : public views::View {
87 public: 81 public:
88 explicit SearchBoxFocusHost(views::Widget* search_box_widget) 82 explicit SearchBoxFocusHost(views::Widget* search_box_widget)
89 : search_box_widget_(search_box_widget) {} 83 : search_box_widget_(search_box_widget) {}
90 84
91 ~SearchBoxFocusHost() override {} 85 ~SearchBoxFocusHost() override {}
92 86
93 views::FocusTraversable* GetFocusTraversable() override { 87 views::FocusTraversable* GetFocusTraversable() override {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 app_list_main_view_(nullptr), 189 app_list_main_view_(nullptr),
196 speech_view_(nullptr), 190 speech_view_(nullptr),
197 search_box_focus_host_(nullptr), 191 search_box_focus_host_(nullptr),
198 search_box_widget_(nullptr), 192 search_box_widget_(nullptr),
199 search_box_view_(nullptr), 193 search_box_view_(nullptr),
200 app_list_state_(PEEKING), 194 app_list_state_(PEEKING),
201 display_observer_(this), 195 display_observer_(this),
202 overlay_view_(nullptr), 196 overlay_view_(nullptr),
203 animation_observer_(new HideViewAnimationObserver()) { 197 animation_observer_(new HideViewAnimationObserver()) {
204 CHECK(delegate); 198 CHECK(delegate);
205 199 IsFullscreenAppListEnabled();
206 delegate_->GetSpeechUI()->AddObserver(this); 200 delegate_->GetSpeechUI()->AddObserver(this);
207 201
208 if (IsFullscreenAppListEnabled()) 202 if (is_fullscreen_app_list_enabled_)
209 display_observer_.Add(display::Screen::GetScreen()); 203 display_observer_.Add(display::Screen::GetScreen());
210 } 204 }
211 205
212 AppListView::~AppListView() { 206 AppListView::~AppListView() {
213 delegate_->GetSpeechUI()->RemoveObserver(this); 207 delegate_->GetSpeechUI()->RemoveObserver(this);
214 animation_observer_.reset(); 208 animation_observer_.reset();
215 // Remove child views first to ensure no remaining dependencies on delegate_. 209 // Remove child views first to ensure no remaining dependencies on delegate_.
216 RemoveAllChildViews(true); 210 RemoveAllChildViews(true);
217 } 211 }
218 212
219 void AppListView::Initialize(gfx::NativeView parent, int initial_apps_page) { 213 void AppListView::Initialize(gfx::NativeView parent, int initial_apps_page) {
220 base::Time start_time = base::Time::Now(); 214 base::Time start_time = base::Time::Now();
215 IsFullscreenAppListEnabled();
221 InitContents(parent, initial_apps_page); 216 InitContents(parent, initial_apps_page);
222 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); 217 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
223 set_color(kContentsBackgroundColor); 218 set_color(kContentsBackgroundColor);
224 set_parent_window(parent); 219 set_parent_window(parent);
225 220
226 if (IsFullscreenAppListEnabled()) 221 if (is_fullscreen_app_list_enabled_)
227 InitializeFullscreen(parent, initial_apps_page); 222 InitializeFullscreen(parent, initial_apps_page);
228 else 223 else
229 InitializeBubble(parent, initial_apps_page); 224 InitializeBubble(parent, initial_apps_page);
230 225
231 InitChildWidgets(); 226 InitChildWidgets();
232 AddChildView(overlay_view_); 227 AddChildView(overlay_view_);
233 228
234 if (IsFullscreenAppListEnabled()) 229 if (is_fullscreen_app_list_enabled_)
235 SetState(app_list_state_); 230 SetState(app_list_state_);
236 231
237 if (delegate_) 232 if (delegate_)
238 delegate_->ViewInitialized(); 233 delegate_->ViewInitialized();
239 234
240 UMA_HISTOGRAM_TIMES("Apps.AppListCreationTime", 235 UMA_HISTOGRAM_TIMES("Apps.AppListCreationTime",
241 base::Time::Now() - start_time); 236 base::Time::Now() - start_time);
242 } 237 }
243 238
244 void AppListView::SetBubbleArrow(views::BubbleBorder::Arrow arrow) { 239 void AppListView::SetBubbleArrow(views::BubbleBorder::Arrow arrow) {
245 GetBubbleFrameView()->bubble_border()->set_arrow(arrow); 240 GetBubbleFrameView()->bubble_border()->set_arrow(arrow);
246 SizeToContents(); // Recalcuates with new border. 241 SizeToContents(); // Recalcuates with new border.
247 GetBubbleFrameView()->SchedulePaint(); 242 GetBubbleFrameView()->SchedulePaint();
248 } 243 }
249 244
250 void AppListView::MaybeSetAnchorPoint(const gfx::Point& anchor_point) { 245 void AppListView::MaybeSetAnchorPoint(const gfx::Point& anchor_point) {
251 // if the AppListView is a bubble 246 // if the AppListView is a bubble
252 if (!IsFullscreenAppListEnabled()) 247 if (!is_fullscreen_app_list_enabled_)
253 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size())); 248 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size()));
254 } 249 }
255 250
256 void AppListView::SetDragAndDropHostOfCurrentAppList( 251 void AppListView::SetDragAndDropHostOfCurrentAppList(
257 ApplicationDragAndDropHost* drag_and_drop_host) { 252 ApplicationDragAndDropHost* drag_and_drop_host) {
258 app_list_main_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); 253 app_list_main_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host);
259 } 254 }
260 255
261 void AppListView::ShowWhenReady() { 256 void AppListView::ShowWhenReady() {
262 app_list_main_view_->ShowAppListWhenReady(); 257 app_list_main_view_->ShowAppListWhenReady();
263 } 258 }
264 259
265 void AppListView::UpdateBounds() { 260 void AppListView::UpdateBounds() {
266 // if the AppListView is a bubble 261 // if the AppListView is a bubble
267 if (!IsFullscreenAppListEnabled()) 262 if (!is_fullscreen_app_list_enabled_)
268 SizeToContents(); 263 SizeToContents();
269 } 264 }
270 265
271 void AppListView::SetAppListOverlayVisible(bool visible) { 266 void AppListView::SetAppListOverlayVisible(bool visible) {
272 DCHECK(overlay_view_); 267 DCHECK(overlay_view_);
273 268
274 // Display the overlay immediately so we can begin the animation. 269 // Display the overlay immediately so we can begin the animation.
275 overlay_view_->SetVisible(true); 270 overlay_view_->SetVisible(true);
276 271
277 ui::ScopedLayerAnimationSettings settings( 272 ui::ScopedLayerAnimationSettings settings(
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 ->pagination_model(); 345 ->pagination_model();
351 } 346 }
352 347
353 void AppListView::InitContents(gfx::NativeView parent, int initial_apps_page) { 348 void AppListView::InitContents(gfx::NativeView parent, int initial_apps_page) {
354 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440224 and 349 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440224 and
355 // crbug.com/441028 are fixed. 350 // crbug.com/441028 are fixed.
356 tracked_objects::ScopedTracker tracking_profile( 351 tracked_objects::ScopedTracker tracking_profile(
357 FROM_HERE_WITH_EXPLICIT_FUNCTION( 352 FROM_HERE_WITH_EXPLICIT_FUNCTION(
358 "440224, 441028 AppListView::InitContents")); 353 "440224, 441028 AppListView::InitContents"));
359 354
360 if (IsFullscreenAppListEnabled()) { 355 if (is_fullscreen_app_list_enabled_) {
361 // The shield view that colors the background of the app list and makes it 356 // The shield view that colors the background of the app list and makes it
362 // transparent. 357 // transparent.
363 app_list_background_shield_ = new views::View; 358 app_list_background_shield_ = new views::View;
364 app_list_background_shield_->SetPaintToLayer(ui::LAYER_SOLID_COLOR); 359 app_list_background_shield_->SetPaintToLayer(ui::LAYER_SOLID_COLOR);
365 app_list_background_shield_->layer()->SetColor(SK_ColorBLACK); 360 app_list_background_shield_->layer()->SetColor(SK_ColorBLACK);
366 app_list_background_shield_->layer()->SetOpacity(kAppListOpacity); 361 app_list_background_shield_->layer()->SetOpacity(kAppListOpacity);
367 AddChildView(app_list_background_shield_); 362 AddChildView(app_list_background_shield_);
368 } 363 }
369 app_list_main_view_ = new AppListMainView(delegate_, this); 364 app_list_main_view_ = new AppListMainView(delegate_, this);
370 AddChildView(app_list_main_view_); 365 AddChildView(app_list_main_view_);
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 } 584 }
590 585
591 void AppListView::GetWidgetHitTestMask(gfx::Path* mask) const { 586 void AppListView::GetWidgetHitTestMask(gfx::Path* mask) const {
592 DCHECK(mask); 587 DCHECK(mask);
593 DCHECK(GetBubbleFrameView()); 588 DCHECK(GetBubbleFrameView());
594 589
595 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds())); 590 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds()));
596 } 591 }
597 592
598 void AppListView::OnMouseEvent(ui::MouseEvent* event) { 593 void AppListView::OnMouseEvent(ui::MouseEvent* event) {
599 if (!IsFullscreenAppListEnabled()) 594 if (!is_fullscreen_app_list_enabled_)
600 return; 595 return;
601 596
602 switch (event->type()) { 597 switch (event->type()) {
603 case ui::ET_MOUSE_PRESSED: 598 case ui::ET_MOUSE_PRESSED:
604 StartDrag(event->location()); 599 StartDrag(event->location());
605 event->SetHandled(); 600 event->SetHandled();
606 break; 601 break;
607 case ui::ET_MOUSE_DRAGGED: 602 case ui::ET_MOUSE_DRAGGED:
608 UpdateDrag(event->location()); 603 UpdateDrag(event->location());
609 event->SetHandled(); 604 event->SetHandled();
610 break; 605 break;
611 case ui::ET_MOUSE_RELEASED: 606 case ui::ET_MOUSE_RELEASED:
612 EndDrag(event->location()); 607 EndDrag(event->location());
613 event->SetHandled(); 608 event->SetHandled();
614 break; 609 break;
615 default: 610 default:
616 break; 611 break;
617 } 612 }
618 } 613 }
619 614
620 void AppListView::OnGestureEvent(ui::GestureEvent* event) { 615 void AppListView::OnGestureEvent(ui::GestureEvent* event) {
621 if (!IsFullscreenAppListEnabled()) 616 if (!is_fullscreen_app_list_enabled_)
622 return; 617 return;
623 618
624 switch (event->type()) { 619 switch (event->type()) {
625 case ui::ET_GESTURE_SCROLL_BEGIN: 620 case ui::ET_GESTURE_SCROLL_BEGIN:
626 StartDrag(event->location()); 621 StartDrag(event->location());
627 event->SetHandled(); 622 event->SetHandled();
628 break; 623 break;
629 case ui::ET_GESTURE_SCROLL_UPDATE: 624 case ui::ET_GESTURE_SCROLL_UPDATE:
630 last_fling_velocity_ = event->details().velocity_y(); 625 last_fling_velocity_ = event->details().velocity_y();
631 UpdateDrag(event->location()); 626 UpdateDrag(event->location());
632 event->SetHandled(); 627 event->SetHandled();
633 break; 628 break;
634 case ui::ET_GESTURE_END: 629 case ui::ET_GESTURE_END:
635 EndDrag(event->location()); 630 EndDrag(event->location());
636 event->SetHandled(); 631 event->SetHandled();
637 break; 632 break;
638 default: 633 default:
639 break; 634 break;
640 } 635 }
641 } 636 }
642 637
643 bool AppListView::AcceleratorPressed(const ui::Accelerator& accelerator) { 638 bool AppListView::AcceleratorPressed(const ui::Accelerator& accelerator) {
644 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); 639 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code());
645 640
646 // If the ContentsView does not handle the back action, then this is the 641 // If the ContentsView does not handle the back action, then this is the
647 // top level, so we close the app list. 642 // top level, so we close the app list.
648 if (!app_list_main_view_->contents_view()->Back()) { 643 if (!app_list_main_view_->contents_view()->Back()) {
649 if (IsFullscreenAppListEnabled()) { 644 if (is_fullscreen_app_list_enabled_) {
650 SetState(CLOSED); 645 SetState(CLOSED);
651 } else { 646 } else {
652 app_list_main_view_->Close(); 647 app_list_main_view_->Close();
653 delegate_->Dismiss(); 648 delegate_->Dismiss();
654 } 649 }
655 GetWidget()->Deactivate(); 650 GetWidget()->Deactivate();
656 } 651 }
657 652
658 // Don't let DialogClientView handle the accelerator. 653 // Don't let DialogClientView handle the accelerator.
659 return true; 654 return true;
(...skipping 14 matching lines...) Expand all
674 if (speech_view_) { 669 if (speech_view_) {
675 gfx::Rect speech_bounds = centered_bounds; 670 gfx::Rect speech_bounds = centered_bounds;
676 int preferred_height = speech_view_->GetPreferredSize().height(); 671 int preferred_height = speech_view_->GetPreferredSize().height();
677 speech_bounds.Inset(kSpeechUIMargin, kSpeechUIMargin); 672 speech_bounds.Inset(kSpeechUIMargin, kSpeechUIMargin);
678 speech_bounds.set_height( 673 speech_bounds.set_height(
679 std::min(speech_bounds.height(), preferred_height)); 674 std::min(speech_bounds.height(), preferred_height));
680 speech_bounds.Inset(-speech_view_->GetInsets()); 675 speech_bounds.Inset(-speech_view_->GetInsets());
681 speech_view_->SetBoundsRect(speech_bounds); 676 speech_view_->SetBoundsRect(speech_bounds);
682 } 677 }
683 678
684 if (IsFullscreenAppListEnabled()) { 679 if (is_fullscreen_app_list_enabled_) {
685 app_list_main_view_->contents_view()->Layout(); 680 app_list_main_view_->contents_view()->Layout();
686 app_list_background_shield_->SetBoundsRect(contents_bounds); 681 app_list_background_shield_->SetBoundsRect(contents_bounds);
687 } 682 }
688 } 683 }
689 684
690 void AppListView::SchedulePaintInRect(const gfx::Rect& rect) { 685 void AppListView::SchedulePaintInRect(const gfx::Rect& rect) {
691 BubbleDialogDelegateView::SchedulePaintInRect(rect); 686 BubbleDialogDelegateView::SchedulePaintInRect(rect);
692 if (GetBubbleFrameView()) 687 if (GetBubbleFrameView())
693 GetBubbleFrameView()->SchedulePaint(); 688 GetBubbleFrameView()->SchedulePaint();
694 } 689 }
(...skipping 16 matching lines...) Expand all
711 break; 706 break;
712 case CLOSED: 707 case CLOSED:
713 app_list_main_view_->Close(); 708 app_list_main_view_->Close();
714 delegate_->Dismiss(); 709 delegate_->Dismiss();
715 break; 710 break;
716 } 711 }
717 fullscreen_widget_->SetBounds(new_widget_bounds); 712 fullscreen_widget_->SetBounds(new_widget_bounds);
718 app_list_state_ = new_state; 713 app_list_state_ = new_state;
719 } 714 }
720 715
716 void AppListView::IsFullscreenAppListEnabled() {
xiyuan 2017/06/12 22:33:15 Get rid of this function and just initialize |is_f
newcomer 2017/06/12 23:48:17 Done.
717 // Cache this value to avoid repeated lookup.
718 is_fullscreen_app_list_enabled_ = features::IsFullscreenAppListEnabled();
719 }
720
721 void AppListView::OnWidgetDestroying(views::Widget* widget) { 721 void AppListView::OnWidgetDestroying(views::Widget* widget) {
722 BubbleDialogDelegateView::OnWidgetDestroying(widget); 722 BubbleDialogDelegateView::OnWidgetDestroying(widget);
723 if (delegate_ && widget == GetWidget()) 723 if (delegate_ && widget == GetWidget())
724 delegate_->ViewClosing(); 724 delegate_->ViewClosing();
725 } 725 }
726 726
727 void AppListView::OnWidgetVisibilityChanged(views::Widget* widget, 727 void AppListView::OnWidgetVisibilityChanged(views::Widget* widget,
728 bool visible) { 728 bool visible) {
729 BubbleDialogDelegateView::OnWidgetVisibilityChanged(widget, visible); 729 BubbleDialogDelegateView::OnWidgetVisibilityChanged(widget, visible);
730 730
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 // Refocus the search box. However, if the app list widget does not have 797 // Refocus the search box. However, if the app list widget does not have
798 // focus, it means another window has already taken focus, and we *must not* 798 // focus, it means another window has already taken focus, and we *must not*
799 // focus the search box (or we would steal focus back into the app list). 799 // focus the search box (or we would steal focus back into the app list).
800 if (GetWidget()->IsActive()) 800 if (GetWidget()->IsActive())
801 search_box_view_->search_box()->RequestFocus(); 801 search_box_view_->search_box()->RequestFocus();
802 } 802 }
803 } 803 }
804 804
805 void AppListView::OnDisplayMetricsChanged(const display::Display& display, 805 void AppListView::OnDisplayMetricsChanged(const display::Display& display,
806 uint32_t changed_metrics) { 806 uint32_t changed_metrics) {
807 if (!IsFullscreenAppListEnabled()) 807 if (!is_fullscreen_app_list_enabled_)
808 return; 808 return;
809 809
810 // Set the |fullscreen_widget_| size to fit the new display metrics. 810 // Set the |fullscreen_widget_| size to fit the new display metrics.
811 gfx::Size size = display::Screen::GetScreen() 811 gfx::Size size = display::Screen::GetScreen()
812 ->GetDisplayNearestView(parent_window()) 812 ->GetDisplayNearestView(parent_window())
813 .work_area() 813 .work_area()
814 .size(); 814 .size();
815 size.Enlarge(0, kShelfSize); 815 size.Enlarge(0, kShelfSize);
816 fullscreen_widget_->SetSize(size); 816 fullscreen_widget_->SetSize(size);
817 817
818 // Update the |fullscreen_widget_| bounds to accomodate the new work area. 818 // Update the |fullscreen_widget_| bounds to accomodate the new work area.
819 SetState(app_list_state_); 819 SetState(app_list_state_);
820 } 820 }
821 821
822 } // namespace app_list 822 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698