Chromium Code Reviews| Index: ui/app_list/views/app_list_view.cc |
| diff --git a/ui/app_list/views/app_list_view.cc b/ui/app_list/views/app_list_view.cc |
| index 2a1be91f97cb2a39c98e458b0cd518b89c0b5d5e..349d4a2be5cec021baf8bb34ba222df213f08d7f 100644 |
| --- a/ui/app_list/views/app_list_view.cc |
| +++ b/ui/app_list/views/app_list_view.cc |
| @@ -124,15 +124,18 @@ class SearchBoxWindowTargeter : public wm::MaskedWindowTargeter { |
| DISALLOW_COPY_AND_ASSIGN(SearchBoxWindowTargeter); |
| }; |
| +// Checks if the fullscreen app list has been enabled via cmd line switch. |
|
vadimt
2017/04/19 00:57:15
Returns whether ...
newcomer
2017/04/20 19:59:02
Done.
|
| +bool IsFullscreenAppListEnabled() { |
| + return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kEnableFullscreenAppList); |
| +} |
| + |
| } // namespace |
| // An animation observer to hide the view at the end of the animation. |
| class HideViewAnimationObserver : public ui::ImplicitAnimationObserver { |
| public: |
| - HideViewAnimationObserver() |
| - : frame_(NULL), |
| - target_(NULL) { |
| - } |
| + HideViewAnimationObserver() : frame_(NULL), target_(NULL) {} |
| ~HideViewAnimationObserver() override { |
| if (target_) |
| @@ -190,6 +193,79 @@ AppListView::~AppListView() { |
| RemoveAllChildViews(true); |
| } |
| +void AppListView::InitializeFullscreenHelper( |
| + gfx::NativeView parent, |
| + int initial_apps_page, |
| + const gfx::Rect display_work_area_bounds) { |
| + InitContents(parent, initial_apps_page); |
| + AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
| + set_color(kContentsBackgroundColor); |
| + views::Widget* widget = new views::Widget; |
| + views::Widget::InitParams app_list_overlay_view_params( |
| + views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| + |
| + app_list_overlay_view_params.parent = parent; |
| + app_list_overlay_view_params.delegate = this; |
| + |
| + widget->Init(app_list_overlay_view_params); |
| + widget->SetBounds(display_work_area_bounds); |
| + widget->GetLayer()->SetFillsBoundsOpaquely(false); |
| + widget->GetLayer()->SetBackgroundBlur(10); |
| + |
| + InitChildWidgets(); |
| + overlay_view_ = new AppListOverlayView(0 /* no corners */); |
| + AddChildView(overlay_view_); |
| + if (delegate_) |
| + delegate_->ViewInitialized(); |
| +} |
| + |
| +void AppListView::InitializeBubbleHelper(gfx::NativeView parent, |
| + int initial_apps_page) { |
| + InitContents(parent, initial_apps_page); |
|
sky
2017/04/19 15:18:51
There is a lot of similar code in the two function
newcomer
2017/04/20 19:59:02
I've refactored the repeated code. Do you have an
|
| + AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
| + set_margins(gfx::Insets()); |
| + set_parent_window(parent); |
| + set_close_on_deactivate(false); |
| + set_shadow(views::BubbleBorder::NO_ASSETS); |
| + set_color(kContentsBackgroundColor); |
| + |
| + // This creates the app list widget. (Before this, child widgets cannot be |
| + // created.) |
| + views::BubbleDialogDelegateView::CreateBubble(this); |
| + |
| + SetBubbleArrow(views::BubbleBorder::FLOAT); |
| + // We can now create the internal widgets. |
| + |
| + InitChildWidgets(); |
| + aura::Window* window = GetWidget()->GetNativeWindow(); |
| + window->SetEventTargeter(base::MakeUnique<views::BubbleWindowTargeter>(this)); |
| + |
| + const int kOverlayCornerRadius = |
| + GetBubbleFrameView()->bubble_border()->GetBorderCornerRadius(); |
| + overlay_view_ = new AppListOverlayView(kOverlayCornerRadius); |
| + overlay_view_->SetBoundsRect(GetContentsBounds()); |
| + AddChildView(overlay_view_); |
| + |
| + if (delegate_) |
| + delegate_->ViewInitialized(); |
| +} |
| + |
| +void AppListView::Initialize(gfx::NativeView parent, |
| + int initial_apps_page, |
| + const gfx::Rect display_work_area_bounds) { |
| + base::Time start_time = base::Time::Now(); |
| + |
| + if (IsFullscreenAppListEnabled()) { |
| + InitializeFullscreenHelper(parent, initial_apps_page, |
| + display_work_area_bounds); |
| + } else { |
| + InitializeBubbleHelper(parent, initial_apps_page); |
| + } |
| + |
| + UMA_HISTOGRAM_TIMES("Apps.AppListCreationTime", |
| + base::Time::Now() - start_time); |
| +} |
| + |
| void AppListView::InitAsBubble(gfx::NativeView parent, int initial_apps_page) { |
| base::Time start_time = base::Time::Now(); |
| @@ -232,7 +308,11 @@ void AppListView::SetBubbleArrow(views::BubbleBorder::Arrow arrow) { |
| } |
| void AppListView::SetAnchorPoint(const gfx::Point& anchor_point) { |
|
vadimt
2017/04/19 00:57:15
MaybeSetAnchorPoint
newcomer
2017/04/20 19:59:01
Done.
|
| - SetAnchorRect(gfx::Rect(anchor_point, gfx::Size())); |
| + // if the AppListView is a bubble |
| + if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + app_list::switches::kEnableFullscreenAppList)) { |
| + SetAnchorRect(gfx::Rect(anchor_point, gfx::Size())); |
| + } |
| } |
| void AppListView::SetDragAndDropHostOfCurrentAppList( |
| @@ -250,7 +330,11 @@ void AppListView::CloseAppList() { |
| } |
| void AppListView::UpdateBounds() { |
| - SizeToContents(); |
| + // if the AppListView is a bubble |
| + if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + app_list::switches::kEnableFullscreenAppList)) { |
| + SizeToContents(); |
| + } |
| } |
| void AppListView::SetAppListOverlayVisible(bool visible) { |
| @@ -304,6 +388,10 @@ void AppListView::OnPaint(gfx::Canvas* canvas) { |
| } |
| } |
| +const char* AppListView::GetClassName() const { |
| + return "AppListView"; |
| +} |
| + |
| bool AppListView::ShouldHandleSystemCommands() const { |
| return true; |
| } |
| @@ -343,7 +431,6 @@ void AppListView::InitContents(gfx::NativeView parent, int initial_apps_page) { |
| app_list_main_view_->SetPaintToLayer(); |
| app_list_main_view_->layer()->SetFillsBoundsOpaquely(false); |
| app_list_main_view_->layer()->SetMasksToBounds(true); |
| - |
| // This will be added to the |search_box_widget_| after the app list widget is |
| // initialized. |
| search_box_view_ = new SearchBoxView(app_list_main_view_, delegate_); |
| @@ -410,9 +497,8 @@ void AppListView::InitChildWidgets() { |
| app_list_main_view_->contents_view()->Layout(); |
| } |
| -void AppListView::OnBeforeBubbleWidgetInit( |
| - views::Widget::InitParams* params, |
| - views::Widget* widget) const { |
| +void AppListView::OnBeforeBubbleWidgetInit(views::Widget::InitParams* params, |
| + views::Widget* widget) const { |
| if (!params->native_widget) { |
| views::ViewsDelegate* views_delegate = views::ViewsDelegate::GetInstance(); |
| if (views_delegate && !views_delegate->native_widget_factory().is_null()) { |
| @@ -441,8 +527,7 @@ void AppListView::GetWidgetHitTestMask(gfx::Path* mask) const { |
| DCHECK(mask); |
| DCHECK(GetBubbleFrameView()); |
| - mask->addRect(gfx::RectToSkRect( |
| - GetBubbleFrameView()->GetContentsBounds())); |
| + mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds())); |
| } |
| bool AppListView::AcceleratorPressed(const ui::Accelerator& accelerator) { |
| @@ -475,8 +560,8 @@ void AppListView::Layout() { |
| gfx::Rect speech_bounds = centered_bounds; |
| int preferred_height = speech_view_->GetPreferredSize().height(); |
| speech_bounds.Inset(kSpeechUIMargin, kSpeechUIMargin); |
| - speech_bounds.set_height(std::min(speech_bounds.height(), |
| - preferred_height)); |
| + speech_bounds.set_height( |
| + std::min(speech_bounds.height(), preferred_height)); |
| speech_bounds.Inset(-speech_view_->GetInsets()); |
| speech_view_->SetBoundsRect(speech_bounds); |
| } |
| @@ -522,8 +607,7 @@ void AppListView::OnSpeechRecognitionStateChanged( |
| animation_observer_->set_frame(GetBubbleFrameView()); |
| gfx::Transform speech_transform; |
| - speech_transform.Translate( |
| - 0, SkFloatToMScalar(kSpeechUIAppearingPosition)); |
| + speech_transform.Translate(0, SkFloatToMScalar(kSpeechUIAppearingPosition)); |
| if (will_appear) |
| speech_view_->layer()->SetTransform(speech_transform); |