Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ash / test / shelf_view_test_api.cc
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:
21   TestAPIAnimationObserver() {}
22   ~TestAPIAnimationObserver() override {}
23
24   // views::BoundsAnimatorObserver overrides:
25   void OnBoundsAnimatorProgressed(views::BoundsAnimator* animator) override {}
26   void OnBoundsAnimatorDone(views::BoundsAnimator* animator) override {
27     base::MessageLoop::current()->Quit();
28   }
29
30  private:
31   DISALLOW_COPY_AND_ASSIGN(TestAPIAnimationObserver);
32 };
33
34 }  // namespace
35
36 namespace ash {
37 namespace test {
38
39 ShelfViewTestAPI::ShelfViewTestAPI(ShelfView* shelf_view)
40     : shelf_view_(shelf_view) {}
41
42 ShelfViewTestAPI::~ShelfViewTestAPI() {
43 }
44
45 int ShelfViewTestAPI::GetButtonCount() {
46   return shelf_view_->view_model_->view_size();
47 }
48
49 ShelfButton* ShelfViewTestAPI::GetButton(int index) {
50   // App list button is not a ShelfButton.
51   if (shelf_view_->model_->items()[index].type == ash::TYPE_APP_LIST)
52     return NULL;
53
54   return static_cast<ShelfButton*>(shelf_view_->view_model_->view_at(index));
55 }
56
57 int ShelfViewTestAPI::GetFirstVisibleIndex() {
58   return shelf_view_->first_visible_index_;
59 }
60
61 int ShelfViewTestAPI::GetLastVisibleIndex() {
62   return shelf_view_->last_visible_index_;
63 }
64
65 bool ShelfViewTestAPI::IsOverflowButtonVisible() {
66   return shelf_view_->overflow_button_->visible();
67 }
68
69 void ShelfViewTestAPI::ShowOverflowBubble() {
70   if (!shelf_view_->IsShowingOverflowBubble())
71     shelf_view_->ToggleOverflowBubble();
72 }
73
74 const gfx::Rect& ShelfViewTestAPI::GetBoundsByIndex(int index) {
75   return shelf_view_->view_model_->view_at(index)->bounds();
76 }
77
78 const gfx::Rect& ShelfViewTestAPI::GetIdealBoundsByIndex(int index) {
79   return shelf_view_->view_model_->ideal_bounds(index);
80 }
81
82 void ShelfViewTestAPI::SetAnimationDuration(int duration_ms) {
83   shelf_view_->bounds_animator_->SetAnimationDuration(duration_ms);
84 }
85
86 void ShelfViewTestAPI::RunMessageLoopUntilAnimationsDone() {
87   if (!shelf_view_->bounds_animator_->IsAnimating())
88     return;
89
90   scoped_ptr<TestAPIAnimationObserver> observer(new TestAPIAnimationObserver());
91   shelf_view_->bounds_animator_->AddObserver(observer.get());
92
93   // This nested loop will quit when TestAPIAnimationObserver's
94   // OnBoundsAnimatorDone is called.
95   base::MessageLoop::current()->Run();
96
97   shelf_view_->bounds_animator_->RemoveObserver(observer.get());
98 }
99
100 OverflowBubble* ShelfViewTestAPI::overflow_bubble() {
101   return shelf_view_->overflow_bubble_.get();
102 }
103
104 gfx::Size ShelfViewTestAPI::GetPreferredSize() {
105   return shelf_view_->GetPreferredSize();
106 }
107
108 int ShelfViewTestAPI::GetButtonSize() {
109   return kShelfButtonSize;
110 }
111
112 int ShelfViewTestAPI::GetButtonSpacing() {
113   return kShelfButtonSpacing;
114 }
115
116 void ShelfViewTestAPI::ButtonPressed(views::Button* sender,
117                                      const ui::Event& event) {
118   return shelf_view_->ButtonPressed(sender, event);
119 }
120
121 bool ShelfViewTestAPI::SameDragType(ShelfItemType typea,
122                                     ShelfItemType typeb) const {
123   return shelf_view_->SameDragType(typea, typeb);
124 }
125
126 void ShelfViewTestAPI::SetShelfDelegate(ShelfDelegate* delegate) {
127   shelf_view_->delegate_ = delegate;
128 }
129
130 gfx::Rect ShelfViewTestAPI::GetBoundsForDragInsertInScreen() {
131   return shelf_view_->GetBoundsForDragInsertInScreen();
132 }
133
134 bool ShelfViewTestAPI::IsRippedOffFromShelf() {
135   return shelf_view_->dragged_off_shelf_;
136 }
137
138 bool ShelfViewTestAPI::DraggedItemFromOverflowToShelf() {
139     return shelf_view_->dragged_off_from_overflow_to_shelf_;
140 }
141
142 }  // namespace test
143 }  // namespace ash