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

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: 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
« no previous file with comments | « no previous file | ui/app_list/views/search_box_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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() { 78 // The switch that is checked to determine if the fullscreen app list feature is
79 // enabled.
80 bool is_fullscreen_app_list_enabled;
xiyuan 2017/06/12 17:24:38 I'd say make this a member of the class that needs
vadimt 2017/06/12 18:16:57 +1. Please don't add non-const global variables.
newcomer 2017/06/12 22:25:58 Done.
newcomer 2017/06/12 22:25:58 Done.
81
82 void IsFullscreenAppListEnabled() {
79 // Cache this value to avoid repeated lookup. 83 // Cache this value to avoid repeated lookup.
80 static bool cached_value = features::IsFullscreenAppListEnabled(); 84 is_fullscreen_app_list_enabled = features::IsFullscreenAppListEnabled();
81 return cached_value;
82 } 85 }
83 86
84 // This view forwards the focus to the search box widget by providing it as a 87 // This view forwards the focus to the search box widget by providing it as a
85 // FocusTraversable when a focus search is provided. 88 // FocusTraversable when a focus search is provided.
86 class SearchBoxFocusHost : public views::View { 89 class SearchBoxFocusHost : public views::View {
87 public: 90 public:
88 explicit SearchBoxFocusHost(views::Widget* search_box_widget) 91 explicit SearchBoxFocusHost(views::Widget* search_box_widget)
89 : search_box_widget_(search_box_widget) {} 92 : search_box_widget_(search_box_widget) {}
90 93
91 ~SearchBoxFocusHost() override {} 94 ~SearchBoxFocusHost() override {}
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 search_box_widget_(nullptr), 201 search_box_widget_(nullptr),
199 search_box_view_(nullptr), 202 search_box_view_(nullptr),
200 app_list_state_(PEEKING), 203 app_list_state_(PEEKING),
201 display_observer_(this), 204 display_observer_(this),
202 overlay_view_(nullptr), 205 overlay_view_(nullptr),
203 animation_observer_(new HideViewAnimationObserver()) { 206 animation_observer_(new HideViewAnimationObserver()) {
204 CHECK(delegate); 207 CHECK(delegate);
205 208
206 delegate_->GetSpeechUI()->AddObserver(this); 209 delegate_->GetSpeechUI()->AddObserver(this);
207 210
208 if (IsFullscreenAppListEnabled()) 211 if (is_fullscreen_app_list_enabled)
209 display_observer_.Add(display::Screen::GetScreen()); 212 display_observer_.Add(display::Screen::GetScreen());
210 } 213 }
211 214
212 AppListView::~AppListView() { 215 AppListView::~AppListView() {
213 delegate_->GetSpeechUI()->RemoveObserver(this); 216 delegate_->GetSpeechUI()->RemoveObserver(this);
214 animation_observer_.reset(); 217 animation_observer_.reset();
215 // Remove child views first to ensure no remaining dependencies on delegate_. 218 // Remove child views first to ensure no remaining dependencies on delegate_.
216 RemoveAllChildViews(true); 219 RemoveAllChildViews(true);
217 } 220 }
218 221
219 void AppListView::Initialize(gfx::NativeView parent, int initial_apps_page) { 222 void AppListView::Initialize(gfx::NativeView parent, int initial_apps_page) {
220 base::Time start_time = base::Time::Now(); 223 base::Time start_time = base::Time::Now();
224 IsFullscreenAppListEnabled();
221 InitContents(parent, initial_apps_page); 225 InitContents(parent, initial_apps_page);
222 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); 226 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
223 set_color(kContentsBackgroundColor); 227 set_color(kContentsBackgroundColor);
224 set_parent_window(parent); 228 set_parent_window(parent);
225 229
226 if (IsFullscreenAppListEnabled()) 230 if (is_fullscreen_app_list_enabled)
227 InitializeFullscreen(parent, initial_apps_page); 231 InitializeFullscreen(parent, initial_apps_page);
228 else 232 else
229 InitializeBubble(parent, initial_apps_page); 233 InitializeBubble(parent, initial_apps_page);
230 234
231 InitChildWidgets(); 235 InitChildWidgets();
232 AddChildView(overlay_view_); 236 AddChildView(overlay_view_);
233 237
234 if (IsFullscreenAppListEnabled()) 238 if (is_fullscreen_app_list_enabled)
235 SetState(app_list_state_); 239 SetState(app_list_state_);
236 240
237 if (delegate_) 241 if (delegate_)
238 delegate_->ViewInitialized(); 242 delegate_->ViewInitialized();
239 243
240 UMA_HISTOGRAM_TIMES("Apps.AppListCreationTime", 244 UMA_HISTOGRAM_TIMES("Apps.AppListCreationTime",
241 base::Time::Now() - start_time); 245 base::Time::Now() - start_time);
242 } 246 }
243 247
244 void AppListView::SetBubbleArrow(views::BubbleBorder::Arrow arrow) { 248 void AppListView::SetBubbleArrow(views::BubbleBorder::Arrow arrow) {
245 GetBubbleFrameView()->bubble_border()->set_arrow(arrow); 249 GetBubbleFrameView()->bubble_border()->set_arrow(arrow);
246 SizeToContents(); // Recalcuates with new border. 250 SizeToContents(); // Recalcuates with new border.
247 GetBubbleFrameView()->SchedulePaint(); 251 GetBubbleFrameView()->SchedulePaint();
248 } 252 }
249 253
250 void AppListView::MaybeSetAnchorPoint(const gfx::Point& anchor_point) { 254 void AppListView::MaybeSetAnchorPoint(const gfx::Point& anchor_point) {
251 // if the AppListView is a bubble 255 // if the AppListView is a bubble
252 if (!IsFullscreenAppListEnabled()) 256 if (!is_fullscreen_app_list_enabled)
253 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size())); 257 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size()));
254 } 258 }
255 259
256 void AppListView::SetDragAndDropHostOfCurrentAppList( 260 void AppListView::SetDragAndDropHostOfCurrentAppList(
257 ApplicationDragAndDropHost* drag_and_drop_host) { 261 ApplicationDragAndDropHost* drag_and_drop_host) {
258 app_list_main_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); 262 app_list_main_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host);
259 } 263 }
260 264
261 void AppListView::ShowWhenReady() { 265 void AppListView::ShowWhenReady() {
262 app_list_main_view_->ShowAppListWhenReady(); 266 app_list_main_view_->ShowAppListWhenReady();
263 } 267 }
264 268
265 void AppListView::UpdateBounds() { 269 void AppListView::UpdateBounds() {
266 // if the AppListView is a bubble 270 // if the AppListView is a bubble
267 if (!IsFullscreenAppListEnabled()) 271 if (!is_fullscreen_app_list_enabled)
268 SizeToContents(); 272 SizeToContents();
269 } 273 }
270 274
271 void AppListView::SetAppListOverlayVisible(bool visible) { 275 void AppListView::SetAppListOverlayVisible(bool visible) {
272 DCHECK(overlay_view_); 276 DCHECK(overlay_view_);
273 277
274 // Display the overlay immediately so we can begin the animation. 278 // Display the overlay immediately so we can begin the animation.
275 overlay_view_->SetVisible(true); 279 overlay_view_->SetVisible(true);
276 280
277 ui::ScopedLayerAnimationSettings settings( 281 ui::ScopedLayerAnimationSettings settings(
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 ->pagination_model(); 354 ->pagination_model();
351 } 355 }
352 356
353 void AppListView::InitContents(gfx::NativeView parent, int initial_apps_page) { 357 void AppListView::InitContents(gfx::NativeView parent, int initial_apps_page) {
354 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440224 and 358 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440224 and
355 // crbug.com/441028 are fixed. 359 // crbug.com/441028 are fixed.
356 tracked_objects::ScopedTracker tracking_profile( 360 tracked_objects::ScopedTracker tracking_profile(
357 FROM_HERE_WITH_EXPLICIT_FUNCTION( 361 FROM_HERE_WITH_EXPLICIT_FUNCTION(
358 "440224, 441028 AppListView::InitContents")); 362 "440224, 441028 AppListView::InitContents"));
359 363
360 if (IsFullscreenAppListEnabled()) { 364 if (is_fullscreen_app_list_enabled) {
361 // The shield view that colors the background of the app list and makes it 365 // The shield view that colors the background of the app list and makes it
362 // transparent. 366 // transparent.
363 app_list_background_shield_ = new views::View; 367 app_list_background_shield_ = new views::View;
364 app_list_background_shield_->SetPaintToLayer(ui::LAYER_SOLID_COLOR); 368 app_list_background_shield_->SetPaintToLayer(ui::LAYER_SOLID_COLOR);
365 app_list_background_shield_->layer()->SetColor(SK_ColorBLACK); 369 app_list_background_shield_->layer()->SetColor(SK_ColorBLACK);
366 app_list_background_shield_->layer()->SetOpacity(kAppListOpacity); 370 app_list_background_shield_->layer()->SetOpacity(kAppListOpacity);
367 AddChildView(app_list_background_shield_); 371 AddChildView(app_list_background_shield_);
368 } 372 }
369 app_list_main_view_ = new AppListMainView(delegate_, this); 373 app_list_main_view_ = new AppListMainView(delegate_, this);
370 AddChildView(app_list_main_view_); 374 AddChildView(app_list_main_view_);
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 } 593 }
590 594
591 void AppListView::GetWidgetHitTestMask(gfx::Path* mask) const { 595 void AppListView::GetWidgetHitTestMask(gfx::Path* mask) const {
592 DCHECK(mask); 596 DCHECK(mask);
593 DCHECK(GetBubbleFrameView()); 597 DCHECK(GetBubbleFrameView());
594 598
595 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds())); 599 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds()));
596 } 600 }
597 601
598 void AppListView::OnMouseEvent(ui::MouseEvent* event) { 602 void AppListView::OnMouseEvent(ui::MouseEvent* event) {
599 if (!IsFullscreenAppListEnabled()) 603 if (!is_fullscreen_app_list_enabled)
600 return; 604 return;
601 605
602 switch (event->type()) { 606 switch (event->type()) {
603 case ui::ET_MOUSE_PRESSED: 607 case ui::ET_MOUSE_PRESSED:
604 StartDrag(event->location()); 608 StartDrag(event->location());
605 event->SetHandled(); 609 event->SetHandled();
606 break; 610 break;
607 case ui::ET_MOUSE_DRAGGED: 611 case ui::ET_MOUSE_DRAGGED:
608 UpdateDrag(event->location()); 612 UpdateDrag(event->location());
609 event->SetHandled(); 613 event->SetHandled();
610 break; 614 break;
611 case ui::ET_MOUSE_RELEASED: 615 case ui::ET_MOUSE_RELEASED:
612 EndDrag(event->location()); 616 EndDrag(event->location());
613 event->SetHandled(); 617 event->SetHandled();
614 break; 618 break;
615 default: 619 default:
616 break; 620 break;
617 } 621 }
618 } 622 }
619 623
620 void AppListView::OnGestureEvent(ui::GestureEvent* event) { 624 void AppListView::OnGestureEvent(ui::GestureEvent* event) {
621 if (!IsFullscreenAppListEnabled()) 625 if (!is_fullscreen_app_list_enabled)
622 return; 626 return;
623 627
624 switch (event->type()) { 628 switch (event->type()) {
625 case ui::ET_GESTURE_SCROLL_BEGIN: 629 case ui::ET_GESTURE_SCROLL_BEGIN:
626 StartDrag(event->location()); 630 StartDrag(event->location());
627 event->SetHandled(); 631 event->SetHandled();
628 break; 632 break;
629 case ui::ET_GESTURE_SCROLL_UPDATE: 633 case ui::ET_GESTURE_SCROLL_UPDATE:
630 last_fling_velocity_ = event->details().velocity_y(); 634 last_fling_velocity_ = event->details().velocity_y();
631 UpdateDrag(event->location()); 635 UpdateDrag(event->location());
632 event->SetHandled(); 636 event->SetHandled();
633 break; 637 break;
634 case ui::ET_GESTURE_END: 638 case ui::ET_GESTURE_END:
635 EndDrag(event->location()); 639 EndDrag(event->location());
636 event->SetHandled(); 640 event->SetHandled();
637 break; 641 break;
638 default: 642 default:
639 break; 643 break;
640 } 644 }
641 } 645 }
642 646
643 bool AppListView::AcceleratorPressed(const ui::Accelerator& accelerator) { 647 bool AppListView::AcceleratorPressed(const ui::Accelerator& accelerator) {
644 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); 648 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code());
645 649
646 // If the ContentsView does not handle the back action, then this is the 650 // If the ContentsView does not handle the back action, then this is the
647 // top level, so we close the app list. 651 // top level, so we close the app list.
648 if (!app_list_main_view_->contents_view()->Back()) { 652 if (!app_list_main_view_->contents_view()->Back()) {
649 if (IsFullscreenAppListEnabled()) { 653 if (is_fullscreen_app_list_enabled) {
650 SetState(CLOSED); 654 SetState(CLOSED);
651 } else { 655 } else {
652 app_list_main_view_->Close(); 656 app_list_main_view_->Close();
653 delegate_->Dismiss(); 657 delegate_->Dismiss();
654 } 658 }
655 GetWidget()->Deactivate(); 659 GetWidget()->Deactivate();
656 } 660 }
657 661
658 // Don't let DialogClientView handle the accelerator. 662 // Don't let DialogClientView handle the accelerator.
659 return true; 663 return true;
(...skipping 14 matching lines...) Expand all
674 if (speech_view_) { 678 if (speech_view_) {
675 gfx::Rect speech_bounds = centered_bounds; 679 gfx::Rect speech_bounds = centered_bounds;
676 int preferred_height = speech_view_->GetPreferredSize().height(); 680 int preferred_height = speech_view_->GetPreferredSize().height();
677 speech_bounds.Inset(kSpeechUIMargin, kSpeechUIMargin); 681 speech_bounds.Inset(kSpeechUIMargin, kSpeechUIMargin);
678 speech_bounds.set_height( 682 speech_bounds.set_height(
679 std::min(speech_bounds.height(), preferred_height)); 683 std::min(speech_bounds.height(), preferred_height));
680 speech_bounds.Inset(-speech_view_->GetInsets()); 684 speech_bounds.Inset(-speech_view_->GetInsets());
681 speech_view_->SetBoundsRect(speech_bounds); 685 speech_view_->SetBoundsRect(speech_bounds);
682 } 686 }
683 687
684 if (IsFullscreenAppListEnabled()) { 688 if (is_fullscreen_app_list_enabled) {
685 app_list_main_view_->contents_view()->Layout(); 689 app_list_main_view_->contents_view()->Layout();
686 app_list_background_shield_->SetBoundsRect(contents_bounds); 690 app_list_background_shield_->SetBoundsRect(contents_bounds);
687 } 691 }
688 } 692 }
689 693
690 void AppListView::SchedulePaintInRect(const gfx::Rect& rect) { 694 void AppListView::SchedulePaintInRect(const gfx::Rect& rect) {
691 BubbleDialogDelegateView::SchedulePaintInRect(rect); 695 BubbleDialogDelegateView::SchedulePaintInRect(rect);
692 if (GetBubbleFrameView()) 696 if (GetBubbleFrameView())
693 GetBubbleFrameView()->SchedulePaint(); 697 GetBubbleFrameView()->SchedulePaint();
694 } 698 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 // Refocus the search box. However, if the app list widget does not have 801 // 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* 802 // 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). 803 // focus the search box (or we would steal focus back into the app list).
800 if (GetWidget()->IsActive()) 804 if (GetWidget()->IsActive())
801 search_box_view_->search_box()->RequestFocus(); 805 search_box_view_->search_box()->RequestFocus();
802 } 806 }
803 } 807 }
804 808
805 void AppListView::OnDisplayMetricsChanged(const display::Display& display, 809 void AppListView::OnDisplayMetricsChanged(const display::Display& display,
806 uint32_t changed_metrics) { 810 uint32_t changed_metrics) {
807 if (!IsFullscreenAppListEnabled()) 811 if (!is_fullscreen_app_list_enabled)
808 return; 812 return;
809 813
810 // Set the |fullscreen_widget_| size to fit the new display metrics. 814 // Set the |fullscreen_widget_| size to fit the new display metrics.
811 gfx::Size size = display::Screen::GetScreen() 815 gfx::Size size = display::Screen::GetScreen()
812 ->GetDisplayNearestView(parent_window()) 816 ->GetDisplayNearestView(parent_window())
813 .work_area() 817 .work_area()
814 .size(); 818 .size();
815 size.Enlarge(0, kShelfSize); 819 size.Enlarge(0, kShelfSize);
816 fullscreen_widget_->SetSize(size); 820 fullscreen_widget_->SetSize(size);
817 821
818 // Update the |fullscreen_widget_| bounds to accomodate the new work area. 822 // Update the |fullscreen_widget_| bounds to accomodate the new work area.
819 SetState(app_list_state_); 823 SetState(app_list_state_);
820 } 824 }
821 825
822 } // namespace app_list 826 } // namespace app_list
OLDNEW
« no previous file with comments | « no previous file | ui/app_list/views/search_box_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698