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