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

Side by Side Diff: ash/shelf/shelf_view.cc

Issue 2191153002: Revert of Replaced BackgroundAnimator with ShelfBackgroundAnimator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 | « ash/shelf/shelf_view.h ('k') | ash/shelf/shelf_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 "ash/shelf/shelf_view.h" 5 #include "ash/shelf/shelf_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 9
10 #include "ash/aura/wm_window_aura.h" 10 #include "ash/aura/wm_window_aura.h"
11 #include "ash/common/ash_constants.h" 11 #include "ash/common/ash_constants.h"
12 #include "ash/common/ash_switches.h" 12 #include "ash/common/ash_switches.h"
13 #include "ash/common/shelf/app_list_button.h" 13 #include "ash/common/shelf/app_list_button.h"
14 #include "ash/common/shelf/overflow_bubble.h" 14 #include "ash/common/shelf/overflow_bubble.h"
15 #include "ash/common/shelf/overflow_bubble_view.h" 15 #include "ash/common/shelf/overflow_bubble_view.h"
16 #include "ash/common/shelf/overflow_button.h" 16 #include "ash/common/shelf/overflow_button.h"
17 #include "ash/common/shelf/shelf_background_animator.h"
18 #include "ash/common/shelf/shelf_button.h" 17 #include "ash/common/shelf/shelf_button.h"
19 #include "ash/common/shelf/shelf_constants.h" 18 #include "ash/common/shelf/shelf_constants.h"
20 #include "ash/common/shelf/shelf_delegate.h" 19 #include "ash/common/shelf/shelf_delegate.h"
21 #include "ash/common/shelf/shelf_menu_model.h" 20 #include "ash/common/shelf/shelf_menu_model.h"
22 #include "ash/common/shelf/shelf_model.h" 21 #include "ash/common/shelf/shelf_model.h"
23 #include "ash/common/shelf/wm_shelf.h" 22 #include "ash/common/shelf/wm_shelf.h"
24 #include "ash/common/shell_delegate.h" 23 #include "ash/common/shell_delegate.h"
25 #include "ash/common/wm/root_window_finder.h" 24 #include "ash/common/wm/root_window_finder.h"
26 #include "ash/common/wm_shell.h" 25 #include "ash/common/wm_shell.h"
27 #include "ash/drag_drop/drag_image_view.h" 26 #include "ash/drag_drop/drag_image_view.h"
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 353
355 DISALLOW_COPY_AND_ASSIGN(StartFadeAnimationDelegate); 354 DISALLOW_COPY_AND_ASSIGN(StartFadeAnimationDelegate);
356 }; 355 };
357 356
358 // static 357 // static
359 const int ShelfView::kMinimumDragDistance = 8; 358 const int ShelfView::kMinimumDragDistance = 8;
360 359
361 ShelfView::ShelfView(ShelfModel* model, 360 ShelfView::ShelfView(ShelfModel* model,
362 ShelfDelegate* delegate, 361 ShelfDelegate* delegate,
363 WmShelf* wm_shelf, 362 WmShelf* wm_shelf,
364 Shelf* shelf, 363 Shelf* shelf)
365 ShelfBackgroundAnimator* background_animator)
366 : model_(model), 364 : model_(model),
367 delegate_(delegate), 365 delegate_(delegate),
368 wm_shelf_(wm_shelf), 366 wm_shelf_(wm_shelf),
369 shelf_(shelf), 367 shelf_(shelf),
370 view_model_(new views::ViewModel), 368 view_model_(new views::ViewModel),
371 first_visible_index_(0), 369 first_visible_index_(0),
372 last_visible_index_(-1), 370 last_visible_index_(-1),
373 overflow_button_(nullptr), 371 overflow_button_(nullptr),
374 owner_overflow_bubble_(nullptr), 372 owner_overflow_bubble_(nullptr),
375 tooltip_(this), 373 tooltip_(this),
376 drag_pointer_(NONE), 374 drag_pointer_(NONE),
377 drag_view_(nullptr), 375 drag_view_(nullptr),
378 start_drag_index_(-1), 376 start_drag_index_(-1),
379 context_menu_id_(0), 377 context_menu_id_(0),
380 leading_inset_(kDefaultLeadingInset), 378 leading_inset_(kDefaultLeadingInset),
381 cancelling_drag_model_changed_(false), 379 cancelling_drag_model_changed_(false),
382 last_hidden_index_(0), 380 last_hidden_index_(0),
383 closing_event_time_(base::TimeTicks()), 381 closing_event_time_(base::TimeTicks()),
384 drag_and_drop_item_pinned_(false), 382 drag_and_drop_item_pinned_(false),
385 drag_and_drop_shelf_id_(0), 383 drag_and_drop_shelf_id_(0),
386 drag_replaced_view_(nullptr), 384 drag_replaced_view_(nullptr),
387 dragged_off_shelf_(false), 385 dragged_off_shelf_(false),
388 snap_back_from_rip_off_view_(nullptr), 386 snap_back_from_rip_off_view_(nullptr),
389 overflow_mode_(false), 387 overflow_mode_(false),
390 main_shelf_(nullptr), 388 main_shelf_(nullptr),
391 dragged_off_from_overflow_to_shelf_(false), 389 dragged_off_from_overflow_to_shelf_(false),
392 is_repost_event_on_same_item_(false), 390 is_repost_event_on_same_item_(false),
393 last_pressed_index_(-1), 391 last_pressed_index_(-1) {
394 background_animator_(background_animator) {
395 DCHECK(model_); 392 DCHECK(model_);
396 DCHECK(delegate_); 393 DCHECK(delegate_);
397 DCHECK(wm_shelf_); 394 DCHECK(wm_shelf_);
398 bounds_animator_.reset(new views::BoundsAnimator(this)); 395 bounds_animator_.reset(new views::BoundsAnimator(this));
399 bounds_animator_->AddObserver(this); 396 bounds_animator_->AddObserver(this);
400 set_context_menu_controller(this); 397 set_context_menu_controller(this);
401 focus_search_.reset(new ShelfFocusSearch(view_model_.get())); 398 focus_search_.reset(new ShelfFocusSearch(view_model_.get()));
402 } 399 }
403 400
404 ShelfView::~ShelfView() { 401 ShelfView::~ShelfView() {
405 bounds_animator_->RemoveObserver(this); 402 bounds_animator_->RemoveObserver(this);
406 model_->RemoveObserver(this); 403 model_->RemoveObserver(this);
407 if (background_animator_)
408 background_animator_->RemoveObserver(this);
409 } 404 }
410 405
411 void ShelfView::Init() { 406 void ShelfView::Init() {
412 model_->AddObserver(this); 407 model_->AddObserver(this);
413 408
414 const ShelfItems& items(model_->items()); 409 const ShelfItems& items(model_->items());
415 for (ShelfItems::const_iterator i = items.begin(); i != items.end(); ++i) { 410 for (ShelfItems::const_iterator i = items.begin(); i != items.end(); ++i) {
416 views::View* child = CreateViewForItem(*i); 411 views::View* child = CreateViewForItem(*i);
417 child->SetPaintToLayer(true); 412 child->SetPaintToLayer(true);
418 view_model_->Add(child, static_cast<int>(i - items.begin())); 413 view_model_->Add(child, static_cast<int>(i - items.begin()));
419 AddChildView(child); 414 AddChildView(child);
420 } 415 }
421 overflow_button_ = new OverflowButton(this, wm_shelf_); 416 overflow_button_ = new OverflowButton(this, wm_shelf_);
422 overflow_button_->set_context_menu_controller(this); 417 overflow_button_->set_context_menu_controller(this);
423 ConfigureChildView(overflow_button_); 418 ConfigureChildView(overflow_button_);
424 AddChildView(overflow_button_); 419 AddChildView(overflow_button_);
425 420
426 if (background_animator_)
427 background_animator_->AddObserver(this);
428
429 // We'll layout when our bounds change. 421 // We'll layout when our bounds change.
430 } 422 }
431 423
432 void ShelfView::OnShelfAlignmentChanged() { 424 void ShelfView::OnShelfAlignmentChanged() {
433 overflow_button_->OnShelfAlignmentChanged(); 425 overflow_button_->OnShelfAlignmentChanged();
434 LayoutToIdealBounds(); 426 LayoutToIdealBounds();
435 for (int i = 0; i < view_model_->view_size(); ++i) { 427 for (int i = 0; i < view_model_->view_size(); ++i) {
436 if (i >= first_visible_index_ && i <= last_visible_index_) 428 if (i >= first_visible_index_ && i <= last_visible_index_)
437 view_model_->view_at(i)->Layout(); 429 view_model_->view_at(i)->Layout();
438 } 430 }
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 void ShelfView::ToggleOverflowBubble() { 1363 void ShelfView::ToggleOverflowBubble() {
1372 if (IsShowingOverflowBubble()) { 1364 if (IsShowingOverflowBubble()) {
1373 overflow_bubble_->Hide(); 1365 overflow_bubble_->Hide();
1374 return; 1366 return;
1375 } 1367 }
1376 1368
1377 if (!overflow_bubble_) 1369 if (!overflow_bubble_)
1378 overflow_bubble_.reset(new OverflowBubble(wm_shelf_)); 1370 overflow_bubble_.reset(new OverflowBubble(wm_shelf_));
1379 1371
1380 ShelfView* overflow_view = 1372 ShelfView* overflow_view =
1381 new ShelfView(model_, delegate_, wm_shelf_, shelf_, nullptr); 1373 new ShelfView(model_, delegate_, wm_shelf_, shelf_);
1382 overflow_view->overflow_mode_ = true; 1374 overflow_view->overflow_mode_ = true;
1383 overflow_view->Init(); 1375 overflow_view->Init();
1384 overflow_view->set_owner_overflow_bubble(overflow_bubble_.get()); 1376 overflow_view->set_owner_overflow_bubble(overflow_bubble_.get());
1385 overflow_view->OnShelfAlignmentChanged(); 1377 overflow_view->OnShelfAlignmentChanged();
1386 overflow_view->main_shelf_ = this; 1378 overflow_view->main_shelf_ = this;
1387 UpdateOverflowRange(overflow_view); 1379 UpdateOverflowRange(overflow_view);
1388 1380
1389 overflow_bubble_->Show(overflow_button_, overflow_view); 1381 overflow_bubble_->Show(overflow_button_, overflow_view);
1390 1382
1391 wm_shelf_->UpdateVisibilityState(); 1383 wm_shelf_->UpdateVisibilityState();
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 } 1540 }
1549 1541
1550 void ShelfView::OnGestureEvent(ui::GestureEvent* event) { 1542 void ShelfView::OnGestureEvent(ui::GestureEvent* event) {
1551 aura::Window* target_window = static_cast<views::View*>(event->target()) 1543 aura::Window* target_window = static_cast<views::View*>(event->target())
1552 ->GetWidget() 1544 ->GetWidget()
1553 ->GetNativeWindow(); 1545 ->GetNativeWindow();
1554 if (gesture_handler_.ProcessGestureEvent(*event, target_window)) 1546 if (gesture_handler_.ProcessGestureEvent(*event, target_window))
1555 event->StopPropagation(); 1547 event->StopPropagation();
1556 } 1548 }
1557 1549
1558 void ShelfView::UpdateShelfItemBackground(int alpha) {
1559 GetAppListButton()->SetBackgroundAlpha(alpha);
1560 overflow_button_->SetBackgroundAlpha(alpha);
1561 }
1562
1563 void ShelfView::ShelfItemAdded(int model_index) { 1550 void ShelfView::ShelfItemAdded(int model_index) {
1564 { 1551 {
1565 base::AutoReset<bool> cancelling_drag(&cancelling_drag_model_changed_, 1552 base::AutoReset<bool> cancelling_drag(&cancelling_drag_model_changed_,
1566 true); 1553 true);
1567 model_index = CancelDrag(model_index); 1554 model_index = CancelDrag(model_index);
1568 } 1555 }
1569 views::View* view = CreateViewForItem(model_->items()[model_index]); 1556 views::View* view = CreateViewForItem(model_->items()[model_index]);
1570 AddChildView(view); 1557 AddChildView(view);
1571 // Hide the view, it'll be made visible when the animation is done. Using 1558 // Hide the view, it'll be made visible when the animation is done. Using
1572 // opacity 0 here to avoid messing with CalculateIdealBounds which touches 1559 // opacity 0 here to avoid messing with CalculateIdealBounds which touches
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
1921 1908
1922 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { 1909 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const {
1923 const gfx::Rect bounds = GetBoundsInScreen(); 1910 const gfx::Rect bounds = GetBoundsInScreen();
1924 int distance = shelf_->SelectValueForShelfAlignment( 1911 int distance = shelf_->SelectValueForShelfAlignment(
1925 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), 1912 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(),
1926 bounds.x() - coordinate.x()); 1913 bounds.x() - coordinate.x());
1927 return distance > 0 ? distance : 0; 1914 return distance > 0 ? distance : 0;
1928 } 1915 }
1929 1916
1930 } // namespace ash 1917 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_view.h ('k') | ash/shelf/shelf_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698