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 "ui/app_list/views/test/apps_grid_view_test_api.h"
6
7#include "ui/app_list/views/app_list_item_view.h"
8#include "ui/app_list/views/apps_grid_view.h"
9#include "ui/events/event.h"
10
11namespace app_list {
12namespace test {
13
14AppsGridViewTestApi::AppsGridViewTestApi(AppsGridView* view)
15    : view_(view) {
16}
17
18AppsGridViewTestApi::~AppsGridViewTestApi() {
19}
20
21views::View* AppsGridViewTestApi::GetViewAtModelIndex(int index) const {
22  return view_->view_model_.view_at(index);
23}
24
25void AppsGridViewTestApi::LayoutToIdealBounds() {
26  if (view_->reorder_timer_.IsRunning()) {
27    view_->reorder_timer_.Stop();
28    view_->OnReorderTimer();
29  }
30  if (view_->folder_dropping_timer_.IsRunning()) {
31    view_->folder_dropping_timer_.Stop();
32    view_->OnFolderDroppingTimer();
33  }
34  view_->bounds_animator_.Cancel();
35  view_->Layout();
36}
37
38void AppsGridViewTestApi::SetPageFlipDelay(int page_flip_delay_in_ms) {
39  view_->page_flip_delay_in_ms_ = page_flip_delay_in_ms;
40}
41
42void AppsGridViewTestApi::PressItemAt(int index) {
43  GetViewAtModelIndex(index)->OnKeyPressed(
44      ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE));
45}
46
47void AppsGridViewTestApi::DisableSynchronousDrag() {
48#if defined(OS_WIN)
49  DCHECK(view_->synchronous_drag_ == NULL) << "DisableSynchronousDrag needs to "
50                                              "be called before "
51                                              "synchronous_drag_ is set up.";
52  view_->use_synchronous_drag_ = false;
53#endif
54}
55
56bool AppsGridViewTestApi::HasPendingPageFlip() const {
57  return view_->page_flip_timer_.IsRunning() ||
58         view_->pagination_model()->has_transition();
59}
60
61}  // namespace test
62}  // namespace app_list
63