Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ash / test / shelf_view_test_api.cc
blobb55690f13b7f0a597a14540b7544a3cad31e474c
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.
5 #include "ash/test/shelf_view_test_api.h"
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"
16 namespace {
18 // A class used to wait for animations.
19 class TestAPIAnimationObserver : public views::BoundsAnimatorObserver {
20 public:
21 TestAPIAnimationObserver() {}
22 virtual ~TestAPIAnimationObserver() {}
24 // views::BoundsAnimatorObserver overrides:
25 virtual void OnBoundsAnimatorProgressed(
26 views::BoundsAnimator* animator) OVERRIDE {}
27 virtual void OnBoundsAnimatorDone(views::BoundsAnimator* animator) OVERRIDE {
28 base::MessageLoop::current()->Quit();
31 private:
32 DISALLOW_COPY_AND_ASSIGN(TestAPIAnimationObserver);
35 } // namespace
37 namespace ash {
38 namespace test {
40 ShelfViewTestAPI::ShelfViewTestAPI(ShelfView* shelf_view)
41 : shelf_view_(shelf_view) {}
43 ShelfViewTestAPI::~ShelfViewTestAPI() {
46 int ShelfViewTestAPI::GetButtonCount() {
47 return shelf_view_->view_model_->view_size();
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;
55 return static_cast<ShelfButton*>(shelf_view_->view_model_->view_at(index));
58 int ShelfViewTestAPI::GetFirstVisibleIndex() {
59 return shelf_view_->first_visible_index_;
62 int ShelfViewTestAPI::GetLastVisibleIndex() {
63 return shelf_view_->last_visible_index_;
66 bool ShelfViewTestAPI::IsOverflowButtonVisible() {
67 return shelf_view_->overflow_button_->visible();
70 void ShelfViewTestAPI::ShowOverflowBubble() {
71 if (!shelf_view_->IsShowingOverflowBubble())
72 shelf_view_->ToggleOverflowBubble();
75 const gfx::Rect& ShelfViewTestAPI::GetBoundsByIndex(int index) {
76 return shelf_view_->view_model_->view_at(index)->bounds();
79 const gfx::Rect& ShelfViewTestAPI::GetIdealBoundsByIndex(int index) {
80 return shelf_view_->view_model_->ideal_bounds(index);
83 void ShelfViewTestAPI::SetAnimationDuration(int duration_ms) {
84 shelf_view_->bounds_animator_->SetAnimationDuration(duration_ms);
87 void ShelfViewTestAPI::RunMessageLoopUntilAnimationsDone() {
88 if (!shelf_view_->bounds_animator_->IsAnimating())
89 return;
91 scoped_ptr<TestAPIAnimationObserver> observer(new TestAPIAnimationObserver());
92 shelf_view_->bounds_animator_->AddObserver(observer.get());
94 // This nested loop will quit when TestAPIAnimationObserver's
95 // OnBoundsAnimatorDone is called.
96 base::MessageLoop::current()->Run();
98 shelf_view_->bounds_animator_->RemoveObserver(observer.get());
101 OverflowBubble* ShelfViewTestAPI::overflow_bubble() {
102 return shelf_view_->overflow_bubble_.get();
105 gfx::Size ShelfViewTestAPI::GetPreferredSize() {
106 return shelf_view_->GetPreferredSize();
109 int ShelfViewTestAPI::GetButtonSize() {
110 return kShelfButtonSize;
113 int ShelfViewTestAPI::GetButtonSpacing() {
114 return kShelfButtonSpacing;
117 void ShelfViewTestAPI::ButtonPressed(views::Button* sender,
118 const ui::Event& event) {
119 return shelf_view_->ButtonPressed(sender, event);
122 bool ShelfViewTestAPI::SameDragType(ShelfItemType typea,
123 ShelfItemType typeb) const {
124 return shelf_view_->SameDragType(typea, typeb);
127 void ShelfViewTestAPI::SetShelfDelegate(ShelfDelegate* delegate) {
128 shelf_view_->delegate_ = delegate;
131 gfx::Rect ShelfViewTestAPI::GetBoundsForDragInsertInScreen() {
132 return shelf_view_->GetBoundsForDragInsertInScreen();
135 bool ShelfViewTestAPI::IsRippedOffFromShelf() {
136 return shelf_view_->dragged_off_shelf_;
139 bool ShelfViewTestAPI::DraggedItemFromOverflowToShelf() {
140 return shelf_view_->dragged_off_from_overflow_to_shelf_;
143 } // namespace test
144 } // namespace ash