Home | History | Annotate | Download | only in overview
      1 // Copyright 2014 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/wm/overview/transparent_activate_window_button.h"
      6 
      7 #include "ash/shell.h"
      8 #include "ash/shell_window_ids.h"
      9 #include "ash/wm/window_state.h"
     10 #include "ui/views/controls/button/custom_button.h"
     11 #include "ui/views/widget/widget.h"
     12 
     13 namespace ash {
     14 
     15 namespace {
     16 
     17 // Transparent button that handles events which activate windows in overview
     18 // mode.
     19 class TransparentButton : public views::CustomButton {
     20  public:
     21   explicit TransparentButton(views::ButtonListener* listener)
     22       : CustomButton(listener) {
     23   }
     24   virtual ~TransparentButton() {}
     25 
     26  private:
     27   DISALLOW_COPY_AND_ASSIGN(TransparentButton);
     28 };
     29 
     30 // Initializes the event handler transparent window.
     31 views::Widget* InitEventHandler(aura::Window* root_window) {
     32   views::Widget* widget = new views::Widget;
     33   views::Widget::InitParams params;
     34   params.type = views::Widget::InitParams::TYPE_POPUP;
     35   params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
     36   params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
     37   params.accept_events = true;
     38   params.parent = Shell::GetContainer(root_window,
     39                                       ash::kShellWindowId_OverlayContainer);
     40   widget->set_focus_on_creation(false);
     41   widget->Init(params);
     42   widget->Show();
     43 
     44   aura::Window* handler = widget->GetNativeWindow();
     45   handler->parent()->StackChildAtBottom(handler);
     46 
     47   return widget;
     48 }
     49 
     50 }  // namespace
     51 
     52 TransparentActivateWindowButton::TransparentActivateWindowButton(
     53     aura::Window* activate_window)
     54     : event_handler_widget_(InitEventHandler(activate_window->GetRootWindow())),
     55       activate_window_(activate_window) {
     56   views::Button* transparent_button = new TransparentButton(this);
     57   transparent_button->SetAccessibleName(activate_window->title());
     58   event_handler_widget_->SetContentsView(transparent_button);
     59 }
     60 
     61 void TransparentActivateWindowButton::SetBounds(const gfx::Rect& bounds) {
     62   event_handler_widget_->SetBounds(bounds);
     63 }
     64 
     65 void TransparentActivateWindowButton::SendFocusAlert() const {
     66   event_handler_widget_->GetContentsView()->
     67       NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, true);
     68 }
     69 
     70 TransparentActivateWindowButton::~TransparentActivateWindowButton() {
     71 }
     72 
     73 void TransparentActivateWindowButton::ButtonPressed(views::Button* sender,
     74                                                     const ui::Event& event) {
     75   wm::GetWindowState(activate_window_)->Activate();
     76 }
     77 
     78 }  // namespace ash
     79