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

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

Issue 770813004: Make app list search box into a Widget. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@matt_remove_dummy_search_box
Patch Set: Created 6 years 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 | « ui/app_list/views/app_list_view.h ('k') | ui/app_list/views/app_list_view_unittest.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/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 150
151 DISALLOW_COPY_AND_ASSIGN(HideViewAnimationObserver); 151 DISALLOW_COPY_AND_ASSIGN(HideViewAnimationObserver);
152 }; 152 };
153 153
154 //////////////////////////////////////////////////////////////////////////////// 154 ////////////////////////////////////////////////////////////////////////////////
155 // AppListView: 155 // AppListView:
156 156
157 AppListView::AppListView(AppListViewDelegate* delegate) 157 AppListView::AppListView(AppListViewDelegate* delegate)
158 : delegate_(delegate), 158 : delegate_(delegate),
159 app_list_main_view_(NULL), 159 app_list_main_view_(NULL),
160 speech_view_(NULL),
Matt Giuca 2014/12/02 07:55:14 nullptr all these.
calamity 2014/12/03 03:31:26 Done.
161 search_box_widget_(NULL),
160 search_box_view_(NULL), 162 search_box_view_(NULL),
161 speech_view_(NULL),
162 experimental_banner_view_(NULL), 163 experimental_banner_view_(NULL),
163 overlay_view_(NULL), 164 overlay_view_(NULL),
164 animation_observer_(new HideViewAnimationObserver()) { 165 animation_observer_(new HideViewAnimationObserver()) {
165 CHECK(delegate); 166 CHECK(delegate);
166 167
167 delegate_->AddObserver(this); 168 delegate_->AddObserver(this);
168 delegate_->GetSpeechUI()->AddObserver(this); 169 delegate_->GetSpeechUI()->AddObserver(this);
169 } 170 }
170 171
171 AppListView::~AppListView() { 172 AppListView::~AppListView() {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 213 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
213 params.parent = parent; 214 params.parent = parent;
214 params.delegate = this; 215 params.delegate = this;
215 widget->Init(params); 216 widget->Init(params);
216 widget->SetBounds(bounds); 217 widget->SetBounds(bounds);
217 // This needs to be set *after* Widget::Init() because BubbleDelegateView sets 218 // This needs to be set *after* Widget::Init() because BubbleDelegateView sets
218 // its own background at OnNativeThemeChanged(), which is called in 219 // its own background at OnNativeThemeChanged(), which is called in
219 // View::AddChildView() which is called at Widget::SetContentsView() to build 220 // View::AddChildView() which is called at Widget::SetContentsView() to build
220 // the views hierarchy in the widget. 221 // the views hierarchy in the widget.
221 set_background(new AppListBackground(0, app_list_main_view_)); 222 set_background(new AppListBackground(0, app_list_main_view_));
223
224 InitChildWidgets();
222 } 225 }
223 226
224 void AppListView::SetBubbleArrow(views::BubbleBorder::Arrow arrow) { 227 void AppListView::SetBubbleArrow(views::BubbleBorder::Arrow arrow) {
225 GetBubbleFrameView()->bubble_border()->set_arrow(arrow); 228 GetBubbleFrameView()->bubble_border()->set_arrow(arrow);
226 SizeToContents(); // Recalcuates with new border. 229 SizeToContents(); // Recalcuates with new border.
227 GetBubbleFrameView()->SchedulePaint(); 230 GetBubbleFrameView()->SchedulePaint();
228 } 231 }
229 232
230 void AppListView::SetAnchorPoint(const gfx::Point& anchor_point) { 233 void AppListView::SetAnchorPoint(const gfx::Point& anchor_point) {
231 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size())); 234 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size()));
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 ->pagination_model(); 351 ->pagination_model();
349 } 352 }
350 353
351 void AppListView::InitContents(gfx::NativeView parent, int initial_apps_page) { 354 void AppListView::InitContents(gfx::NativeView parent, int initial_apps_page) {
352 app_list_main_view_ = new AppListMainView(delegate_); 355 app_list_main_view_ = new AppListMainView(delegate_);
353 AddChildView(app_list_main_view_); 356 AddChildView(app_list_main_view_);
354 app_list_main_view_->SetPaintToLayer(true); 357 app_list_main_view_->SetPaintToLayer(true);
355 app_list_main_view_->SetFillsBoundsOpaquely(false); 358 app_list_main_view_->SetFillsBoundsOpaquely(false);
356 app_list_main_view_->layer()->SetMasksToBounds(true); 359 app_list_main_view_->layer()->SetMasksToBounds(true);
357 360
361 // This will be added to the |search_box_widget_| after the app list widget is
362 // initialized.
358 search_box_view_ = new SearchBoxView(app_list_main_view_, delegate_); 363 search_box_view_ = new SearchBoxView(app_list_main_view_, delegate_);
359 search_box_view_->SetPaintToLayer(true); 364 search_box_view_->SetPaintToLayer(true);
360 search_box_view_->SetFillsBoundsOpaquely(false); 365 search_box_view_->SetFillsBoundsOpaquely(false);
361 search_box_view_->layer()->SetMasksToBounds(true); 366 search_box_view_->layer()->SetMasksToBounds(true);
362 AddChildView(search_box_view_);
363 367
364 app_list_main_view_->Init(parent, initial_apps_page, search_box_view_); 368 app_list_main_view_->Init(parent, initial_apps_page, search_box_view_);
365 369
366 // Speech recognition is available only when the start page exists. 370 // Speech recognition is available only when the start page exists.
367 if (delegate_ && delegate_->IsSpeechRecognitionEnabled()) { 371 if (delegate_ && delegate_->IsSpeechRecognitionEnabled()) {
368 speech_view_ = new SpeechView(delegate_); 372 speech_view_ = new SpeechView(delegate_);
369 speech_view_->SetVisible(false); 373 speech_view_->SetVisible(false);
370 speech_view_->SetPaintToLayer(true); 374 speech_view_->SetPaintToLayer(true);
371 speech_view_->SetFillsBoundsOpaquely(false); 375 speech_view_->SetFillsBoundsOpaquely(false);
372 speech_view_->layer()->SetOpacity(0.0f); 376 speech_view_->layer()->SetOpacity(0.0f);
373 AddChildView(speech_view_); 377 AddChildView(speech_view_);
374 } 378 }
375 379
376 if (app_list::switches::IsExperimentalAppListEnabled()) { 380 if (app_list::switches::IsExperimentalAppListEnabled()) {
377 // Draw a banner in the corner of the experimental app list. 381 // Draw a banner in the corner of the experimental app list.
378 experimental_banner_view_ = new views::ImageView; 382 experimental_banner_view_ = new views::ImageView;
379 const gfx::ImageSkia& experimental_icon = 383 const gfx::ImageSkia& experimental_icon =
380 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 384 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
381 IDR_APP_LIST_EXPERIMENTAL_ICON); 385 IDR_APP_LIST_EXPERIMENTAL_ICON);
382 experimental_banner_view_->SetImage(experimental_icon); 386 experimental_banner_view_->SetImage(experimental_icon);
383 experimental_banner_view_->SetPaintToLayer(true); 387 experimental_banner_view_->SetPaintToLayer(true);
384 experimental_banner_view_->SetFillsBoundsOpaquely(false); 388 experimental_banner_view_->SetFillsBoundsOpaquely(false);
385 AddChildView(experimental_banner_view_); 389 AddChildView(experimental_banner_view_);
386 } 390 }
387 391
388 OnProfilesChanged(); 392 OnProfilesChanged();
389 } 393 }
390 394
395 void AppListView::InitChildWidgets() {
396 DCHECK(search_box_view_);
397
398 app_list_main_view_->InitWidgets();
399
400 // Create the search box widget.
401 views::Widget::InitParams search_box_widget_params(
402 views::Widget::InitParams::TYPE_CONTROL);
403 search_box_widget_params.parent = GetWidget()->GetNativeView();
404 search_box_widget_params.opacity =
405 views::Widget::InitParams::TRANSLUCENT_WINDOW;
406
407 // Create a widget for the SearchBoxView to live in. This widget allows the
408 // SearchBoxView to receive events before the custom launcher page's
Matt Giuca 2014/12/02 07:55:14 I don't really think of it as "before / after", ra
calamity 2014/12/03 03:31:26 Done.
409 // WebContents.
410 search_box_widget_ = new views::Widget;
411 search_box_widget_->Init(search_box_widget_params);
412 search_box_widget_->SetContentsView(search_box_view_);
413
414 Layout();
415 }
416
391 void AppListView::InitAsBubbleInternal(gfx::NativeView parent, 417 void AppListView::InitAsBubbleInternal(gfx::NativeView parent,
392 int initial_apps_page, 418 int initial_apps_page,
393 views::BubbleBorder::Arrow arrow, 419 views::BubbleBorder::Arrow arrow,
394 bool border_accepts_events, 420 bool border_accepts_events,
395 const gfx::Vector2d& anchor_offset) { 421 const gfx::Vector2d& anchor_offset) {
396 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed. 422 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed.
397 tracked_objects::ScopedTracker tracking_profile1( 423 tracked_objects::ScopedTracker tracking_profile1(
398 FROM_HERE_WITH_EXPLICIT_FUNCTION( 424 FROM_HERE_WITH_EXPLICIT_FUNCTION(
399 "431326 AppListView::InitAsBubbleInternal1")); 425 "431326 AppListView::InitAsBubbleInternal1"));
400 426
(...skipping 17 matching lines...) Expand all
418 kArrowOffset - anchor_offset.x())); 444 kArrowOffset - anchor_offset.x()));
419 set_border_accepts_events(border_accepts_events); 445 set_border_accepts_events(border_accepts_events);
420 set_shadow(SupportsShadow() ? views::BubbleBorder::BIG_SHADOW 446 set_shadow(SupportsShadow() ? views::BubbleBorder::BIG_SHADOW
421 : views::BubbleBorder::NO_SHADOW_OPAQUE_BORDER); 447 : views::BubbleBorder::NO_SHADOW_OPAQUE_BORDER);
422 // This creates the app list widget. (Before this, child widgets cannot be 448 // This creates the app list widget. (Before this, child widgets cannot be
423 // created.) 449 // created.)
424 views::BubbleDelegateView::CreateBubble(this); 450 views::BubbleDelegateView::CreateBubble(this);
425 SetBubbleArrow(arrow); 451 SetBubbleArrow(arrow);
426 452
427 // We can now create the internal widgets. 453 // We can now create the internal widgets.
428 app_list_main_view_->InitWidgets(); 454 InitChildWidgets();
429 455
430 #if defined(USE_AURA) 456 #if defined(USE_AURA)
431 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed. 457 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed.
432 tracked_objects::ScopedTracker tracking_profile3( 458 tracked_objects::ScopedTracker tracking_profile3(
433 FROM_HERE_WITH_EXPLICIT_FUNCTION( 459 FROM_HERE_WITH_EXPLICIT_FUNCTION(
434 "431326 AppListView::InitAsBubbleInternal3")); 460 "431326 AppListView::InitAsBubbleInternal3"));
435 461
436 aura::Window* window = GetWidget()->GetNativeWindow(); 462 aura::Window* window = GetWidget()->GetNativeWindow();
437 window->layer()->SetMasksToBounds(true); 463 window->layer()->SetMasksToBounds(true);
438 GetBubbleFrameView()->set_background(new AppListBackground( 464 GetBubbleFrameView()->set_background(new AppListBackground(
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 595
570 app_list_main_view_->SetBoundsRect(centered_bounds); 596 app_list_main_view_->SetBoundsRect(centered_bounds);
571 597
572 // GetDefaultSearchBoxBounds() returns the bounds in |contents_view|'s 598 // GetDefaultSearchBoxBounds() returns the bounds in |contents_view|'s
573 // coordinate, therefore convert it to this coordinate. 599 // coordinate, therefore convert it to this coordinate.
574 ContentsView* contents_view = app_list_main_view_->contents_view(); 600 ContentsView* contents_view = app_list_main_view_->contents_view();
575 // TODO(mgiuca): Position the search box in the center of the page, when 601 // TODO(mgiuca): Position the search box in the center of the page, when
576 // in STATE_START. 602 // in STATE_START.
577 gfx::RectF search_box_bounds = contents_view->GetDefaultSearchBoxBounds(); 603 gfx::RectF search_box_bounds = contents_view->GetDefaultSearchBoxBounds();
578 ConvertRectToTarget(contents_view, this, &search_box_bounds); 604 ConvertRectToTarget(contents_view, this, &search_box_bounds);
579 search_box_view_->SetBoundsRect(gfx::ToNearestRect(search_box_bounds)); 605 if (search_box_widget_) {
Matt Giuca 2014/12/02 07:55:14 Just checking: Can this be a DCHECK or are there s
calamity 2014/12/03 03:31:26 It's null on initial layout unfortunately. This is
606 search_box_widget_->SetBounds(
607 ConvertRectToWidget(gfx::ToNearestRect(search_box_bounds)));
608 }
580 609
581 if (speech_view_) { 610 if (speech_view_) {
582 gfx::Rect speech_bounds = centered_bounds; 611 gfx::Rect speech_bounds = centered_bounds;
583 int preferred_height = speech_view_->GetPreferredSize().height(); 612 int preferred_height = speech_view_->GetPreferredSize().height();
584 speech_bounds.Inset(kSpeechUIMargin, kSpeechUIMargin); 613 speech_bounds.Inset(kSpeechUIMargin, kSpeechUIMargin);
585 speech_bounds.set_height(std::min(speech_bounds.height(), 614 speech_bounds.set_height(std::min(speech_bounds.height(),
586 preferred_height)); 615 preferred_height));
587 speech_bounds.Inset(-speech_view_->GetInsets()); 616 speech_bounds.Inset(-speech_view_->GetInsets());
588 speech_view_->SetBoundsRect(speech_bounds); 617 speech_view_->SetBoundsRect(speech_bounds);
589 } 618 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 speech_view_->layer()->SetTransform(speech_transform); 709 speech_view_->layer()->SetTransform(speech_transform);
681 } 710 }
682 711
683 if (will_appear) 712 if (will_appear)
684 speech_view_->SetVisible(true); 713 speech_view_->SetVisible(true);
685 else 714 else
686 app_list_main_view_->SetVisible(true); 715 app_list_main_view_->SetVisible(true);
687 } 716 }
688 717
689 } // namespace app_list 718 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/app_list_view.h ('k') | ui/app_list/views/app_list_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698