Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ash / wm / overview / transparent_activate_window_button.cc
bloba92e8bbf7d26271c90579ad418622ded36e931d3
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.
5 #include "ash/wm/overview/transparent_activate_window_button.h"
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"
13 namespace ash {
15 namespace {
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) {
24 virtual ~TransparentButton() {}
26 private:
27 DISALLOW_COPY_AND_ASSIGN(TransparentButton);
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();
44 aura::Window* handler = widget->GetNativeWindow();
45 handler->parent()->StackChildAtBottom(handler);
47 return widget;
50 } // namespace
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);
61 void TransparentActivateWindowButton::SetBounds(const gfx::Rect& bounds) {
62 event_handler_widget_->SetBounds(bounds);
65 void TransparentActivateWindowButton::SendFocusAlert() const {
66 event_handler_widget_->GetContentsView()->
67 NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, true);
70 TransparentActivateWindowButton::~TransparentActivateWindowButton() {
73 void TransparentActivateWindowButton::ButtonPressed(views::Button* sender,
74 const ui::Event& event) {
75 wm::GetWindowState(activate_window_)->Activate();
78 } // namespace ash