• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "ash/test/shelf_view_test_api.h"
6 
7 #include "ash/shelf/overflow_button.h"
8 #include "ash/shelf/shelf_button.h"
9 #include "ash/shelf/shelf_constants.h"
10 #include "ash/shelf/shelf_model.h"
11 #include "ash/shelf/shelf_view.h"
12 #include "base/message_loop/message_loop.h"
13 #include "ui/views/animation/bounds_animator.h"
14 #include "ui/views/view_model.h"
15 
16 namespace {
17 
18 // A class used to wait for animations.
19 class TestAPIAnimationObserver : public views::BoundsAnimatorObserver {
20  public:
TestAPIAnimationObserver()21   TestAPIAnimationObserver() {}
~TestAPIAnimationObserver()22   virtual ~TestAPIAnimationObserver() {}
23 
24   // views::BoundsAnimatorObserver overrides:
OnBoundsAnimatorProgressed(views::BoundsAnimator * animator)25   virtual void OnBoundsAnimatorProgressed(
26       views::BoundsAnimator* animator) OVERRIDE {}
OnBoundsAnimatorDone(views::BoundsAnimator * animator)27   virtual void OnBoundsAnimatorDone(views::BoundsAnimator* animator) OVERRIDE {
28     base::MessageLoop::current()->Quit();
29   }
30 
31  private:
32   DISALLOW_COPY_AND_ASSIGN(TestAPIAnimationObserver);
33 };
34 
35 }  // namespace
36 
37 namespace ash {
38 namespace test {
39 
ShelfViewTestAPI(ShelfView * shelf_view)40 ShelfViewTestAPI::ShelfViewTestAPI(ShelfView* shelf_view)
41     : shelf_view_(shelf_view) {}
42 
~ShelfViewTestAPI()43 ShelfViewTestAPI::~ShelfViewTestAPI() {
44 }
45 
GetButtonCount()46 int ShelfViewTestAPI::GetButtonCount() {
47   return shelf_view_->view_model_->view_size();
48 }
49 
GetButton(int index)50 ShelfButton* ShelfViewTestAPI::GetButton(int index) {
51   // App list button is not a ShelfButton.
52   if (shelf_view_->model_->items()[index].type == ash::TYPE_APP_LIST)
53     return NULL;
54 
55   return static_cast<ShelfButton*>(shelf_view_->view_model_->view_at(index));
56 }
57 
GetFirstVisibleIndex()58 int ShelfViewTestAPI::GetFirstVisibleIndex() {
59   return shelf_view_->first_visible_index_;
60 }
61 
GetLastVisibleIndex()62 int ShelfViewTestAPI::GetLastVisibleIndex() {
63   return shelf_view_->last_visible_index_;
64 }
65 
IsOverflowButtonVisible()66 bool ShelfViewTestAPI::IsOverflowButtonVisible() {
67   return shelf_view_->overflow_button_->visible();
68 }
69 
ShowOverflowBubble()70 void ShelfViewTestAPI::ShowOverflowBubble() {
71   if (!shelf_view_->IsShowingOverflowBubble())
72     shelf_view_->ToggleOverflowBubble();
73 }
74 
GetBoundsByIndex(int index)75 const gfx::Rect& ShelfViewTestAPI::GetBoundsByIndex(int index) {
76   return shelf_view_->view_model_->view_at(index)->bounds();
77 }
78 
GetIdealBoundsByIndex(int index)79 const gfx::Rect& ShelfViewTestAPI::GetIdealBoundsByIndex(int index) {
80   return shelf_view_->view_model_->ideal_bounds(index);
81 }
82 
SetAnimationDuration(int duration_ms)83 void ShelfViewTestAPI::SetAnimationDuration(int duration_ms) {
84   shelf_view_->bounds_animator_->SetAnimationDuration(duration_ms);
85 }
86 
RunMessageLoopUntilAnimationsDone()87 void ShelfViewTestAPI::RunMessageLoopUntilAnimationsDone() {
88   if (!shelf_view_->bounds_animator_->IsAnimating())
89     return;
90 
91   scoped_ptr<TestAPIAnimationObserver> observer(new TestAPIAnimationObserver());
92   shelf_view_->bounds_animator_->AddObserver(observer.get());
93 
94   // This nested loop will quit when TestAPIAnimationObserver's
95   // OnBoundsAnimatorDone is called.
96   base::MessageLoop::current()->Run();
97 
98   shelf_view_->bounds_animator_->RemoveObserver(observer.get());
99 }
100 
overflow_bubble()101 OverflowBubble* ShelfViewTestAPI::overflow_bubble() {
102   return shelf_view_->overflow_bubble_.get();
103 }
104 
GetPreferredSize()105 gfx::Size ShelfViewTestAPI::GetPreferredSize() {
106   return shelf_view_->GetPreferredSize();
107 }
108 
GetButtonSize()109 int ShelfViewTestAPI::GetButtonSize() {
110   return kShelfButtonSize;
111 }
112 
GetButtonSpacing()113 int ShelfViewTestAPI::GetButtonSpacing() {
114   return kShelfButtonSpacing;
115 }
116 
SameDragType(ShelfItemType typea,ShelfItemType typeb) const117 bool ShelfViewTestAPI::SameDragType(ShelfItemType typea,
118                                     ShelfItemType typeb) const {
119   return shelf_view_->SameDragType(typea, typeb);
120 }
121 
SetShelfDelegate(ShelfDelegate * delegate)122 void ShelfViewTestAPI::SetShelfDelegate(ShelfDelegate* delegate) {
123   shelf_view_->delegate_ = delegate;
124 }
125 
GetBoundsForDragInsertInScreen()126 gfx::Rect ShelfViewTestAPI::GetBoundsForDragInsertInScreen() {
127   return shelf_view_->GetBoundsForDragInsertInScreen();
128 }
129 
IsRippedOffFromShelf()130 bool ShelfViewTestAPI::IsRippedOffFromShelf() {
131   return shelf_view_->dragged_off_shelf_;
132 }
133 
DraggedItemFromOverflowToShelf()134 bool ShelfViewTestAPI::DraggedItemFromOverflowToShelf() {
135     return shelf_view_->dragged_off_from_overflow_to_shelf_;
136 }
137 
138 }  // namespace test
139 }  // namespace ash
140