summaryrefslogtreecommitdiffstats
path: root/ash/app_list/app_list_view.cc
blob: 9b019ab1c61ec75981d710002422eab016520ed6 (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
// Copyright (c) 2011 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/app_list/app_list_view.h"

#include "ash/app_list/app_list_groups_view.h"
#include "ash/app_list/app_list_item_view.h"
#include "ash/app_list/app_list_model.h"
#include "ash/app_list/app_list_view_delegate.h"
#include "ash/shell.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/widget/widget.h"

namespace ash {

AppListView::AppListView(
    AppListModel* model,
    AppListViewDelegate* delegate,
    const gfx::Rect& bounds,
    const ash::ShellDelegate::SetWidgetCallback& callback)
    : model_(model),
      delegate_(delegate) {
  Init(bounds, callback);
}

AppListView::~AppListView() {
}

void AppListView::Close() {
  if (GetWidget()->IsVisible())
    Shell::GetInstance()->ToggleAppList();
}

void AppListView::Init(const gfx::Rect& bounds,
                       const ShellDelegate::SetWidgetCallback& callback) {
  SetLayoutManager(new views::FillLayout);
  AppListGroupsView* groups_view = new AppListGroupsView(model_.get(), this);
  AddChildView(groups_view);

  views::Widget::InitParams widget_params(
      views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
  widget_params.bounds = bounds;
  widget_params.delegate = this;
  widget_params.keep_on_top = true;
  widget_params.transparent = true;

  views::Widget* widget = new views::Widget;
  widget->Init(widget_params);
  widget->SetContentsView(this);

  callback.Run(widget);
  if (groups_view->GetFocusedTile())
    groups_view->GetFocusedTile()->RequestFocus();
}

bool AppListView::OnKeyPressed(const views::KeyEvent& event) {
  if (event.key_code() == ui::VKEY_ESCAPE) {
    Close();
    return true;
  }

  return false;
}

bool AppListView::OnMousePressed(const views::MouseEvent& event) {
  // If mouse click reaches us, this means user clicks on blank area. So close.
  Close();

  return true;
}

void AppListView::AppListItemActivated(AppListItemView* sender,
                                       int event_flags) {
  if (delegate_.get())
    delegate_->OnAppListItemActivated(sender->model(), event_flags);
  Close();
}

}  // namespace ash