Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / extensions / shell / browser / shell_native_app_window_aura.cc
blobc0158965535884f1092de2bb6385e91daec027db
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 "extensions/shell/browser/shell_native_app_window_aura.h"
7 #include "content/public/browser/web_contents.h"
8 #include "ui/aura/window.h"
9 #include "ui/aura/window_tree_host.h"
10 #include "ui/gfx/geometry/rect.h"
11 #include "ui/wm/core/window_util.h"
13 namespace extensions {
15 ShellNativeAppWindowAura::ShellNativeAppWindowAura(
16 AppWindow* app_window,
17 const AppWindow::CreateParams& params)
18 : ShellNativeAppWindow(app_window, params) {
19 // TODO(yoz): We might have to duplicate this for mac.
20 gfx::Rect bounds = params.GetInitialWindowBounds(GetFrameInsets());
21 bool position_specified =
22 bounds.x() != AppWindow::BoundsSpecification::kUnspecifiedPosition &&
23 bounds.y() != AppWindow::BoundsSpecification::kUnspecifiedPosition;
24 if (!position_specified)
25 bounds.set_origin(GetBounds().origin());
26 SetBounds(bounds);
29 ShellNativeAppWindowAura::~ShellNativeAppWindowAura() {
32 bool ShellNativeAppWindowAura::IsActive() const {
33 // Even though app_shell only supports a single app window, there might be
34 // some sort of system-level dialog open and active.
35 aura::Window* window = GetNativeWindow();
36 return window && wm::IsActiveWindow(window);
39 gfx::NativeWindow ShellNativeAppWindowAura::GetNativeWindow() const {
40 return app_window()->web_contents()->GetNativeView();
43 gfx::Rect ShellNativeAppWindowAura::GetBounds() const {
44 return GetNativeWindow()->GetBoundsInScreen();
47 void ShellNativeAppWindowAura::Show() {
48 GetNativeWindow()->Show();
51 void ShellNativeAppWindowAura::Hide() {
52 GetNativeWindow()->Hide();
55 void ShellNativeAppWindowAura::Activate() {
56 aura::Window* window = GetNativeWindow();
57 if (window)
58 wm::ActivateWindow(window);
61 void ShellNativeAppWindowAura::Deactivate() {
62 aura::Window* window = GetNativeWindow();
63 if (window)
64 wm::DeactivateWindow(window);
67 void ShellNativeAppWindowAura::SetBounds(const gfx::Rect& bounds) {
68 GetNativeWindow()->SetBounds(bounds);
71 } // namespace extensions