Home | History | Annotate | Download | only in shelf
      1 // Copyright 2013 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/shelf/shelf_window_watcher_item_delegate.h"
      6 
      7 #include "ash/shelf/shelf_model.h"
      8 #include "ash/shelf/shelf_util.h"
      9 #include "ash/shell.h"
     10 #include "ash/shell_delegate.h"
     11 #include "ash/wm/window_state.h"
     12 #include "ui/aura/window.h"
     13 #include "ui/views/widget/widget.h"
     14 #include "ui/wm/core/window_animations.h"
     15 
     16 namespace ash {
     17 
     18 ShelfWindowWatcherItemDelegate::ShelfWindowWatcherItemDelegate(
     19     aura::Window* window, ShelfModel* model)
     20     : window_(window),
     21       model_(model) {
     22 }
     23 
     24 ShelfWindowWatcherItemDelegate::~ShelfWindowWatcherItemDelegate() {
     25 }
     26 
     27 void ShelfWindowWatcherItemDelegate::Close() {
     28   views::Widget::GetWidgetForNativeWindow(window_)->Close();
     29 }
     30 
     31 bool ShelfWindowWatcherItemDelegate::ItemSelected(const ui::Event& event) {
     32   wm::WindowState* window_state = wm::GetWindowState(window_);
     33   if (window_state->IsActive()) {
     34     if (event.type() & ui::ET_KEY_RELEASED) {
     35       ::wm::AnimateWindow(window_, ::wm::WINDOW_ANIMATION_TYPE_BOUNCE);
     36     } else {
     37       window_state->Minimize();
     38     }
     39   } else {
     40     window_state->Activate();
     41   }
     42 
     43   return false;
     44 }
     45 
     46 base::string16 ShelfWindowWatcherItemDelegate::GetTitle() {
     47   return GetShelfItemDetailsForWindow(window_)->title;
     48 }
     49 
     50 ui::MenuModel* ShelfWindowWatcherItemDelegate::CreateContextMenu(
     51     aura::Window* root_window) {
     52   ash::ShelfItem item = *(model_->ItemByID(GetShelfIDForWindow(window_)));
     53   return Shell::GetInstance()->delegate()->CreateContextMenu(root_window,
     54                                                              this,
     55                                                              &item);
     56 }
     57 
     58 ShelfMenuModel* ShelfWindowWatcherItemDelegate::CreateApplicationMenu(
     59     int event_flags) {
     60   return NULL;
     61 }
     62 
     63 bool ShelfWindowWatcherItemDelegate::IsDraggable() {
     64   return true;
     65 }
     66 
     67 bool ShelfWindowWatcherItemDelegate::ShouldShowTooltip() {
     68   return true;
     69 }
     70 
     71 }  // namespace ash
     72