summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authortapted <tapted@chromium.org>2014-10-02 16:45:52 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-02 23:46:03 +0000
commit344272ddd4ca47fb56fd6a1ca6a4f1418df2c426 (patch)
treea711d865e73a7a38e3b07b3c28f486671367a5a2 /extensions
parentc4c7e842b3ba77671b74ac263e5fb7217c3dfbfb (diff)
downloadchromium_src-344272ddd4ca47fb56fd6a1ca6a4f1418df2c426.zip
chromium_src-344272ddd4ca47fb56fd6a1ca6a4f1418df2c426.tar.gz
chromium_src-344272ddd4ca47fb56fd6a1ca6a4f1418df2c426.tar.bz2
Move components/native_app_window to extensions/components/native_app_window
There's currently a dependency cycle between gyp files: components.gyp and extensions.gyp. extensions.gyp depends on a number of components, and two components depend on exetensions.gyp. These are: - components/renderer_context_menu/ - components/native_app_window/ (more recently) renderer_context_menu has an "optional" extensions dependency, which can be skipped when ENABLE_EXTENSIONS is not defined. Still, it is necessary for renderer_context_menu.gyp to omit its extensions.gyp dependency and build as a static library. For native_app_window, since it is not compiled on Mac, the gyp circular check is not performed on the bots. This CL fixes the layering by adding a folder, src/extensions/components. Things here may depend on extensions, but not on other extensions/components folders in a way that creates a cycle. This also allows the benefits of a component-architecture to make sense of interdependencies between the ~1337 files under src/extensions. This layout also makes it clear that by depending on one of these components, a target is also depending on src/extensions. Currently, this is not clear. BUG=35878, 418455 TBR=reed@google.com Review URL: https://codereview.chromium.org/606953002 Cr-Commit-Position: refs/heads/master@{#297952}
Diffstat (limited to 'extensions')
-rw-r--r--extensions/DEPS1
-rw-r--r--extensions/components/DEPS7
-rw-r--r--extensions/components/README11
-rw-r--r--extensions/components/extensions_components.gyp19
-rw-r--r--extensions/components/native_app_window.gypi27
-rw-r--r--extensions/components/native_app_window/BUILD.gn20
-rw-r--r--extensions/components/native_app_window/DEPS4
-rw-r--r--extensions/components/native_app_window/OWNERS3
-rw-r--r--extensions/components/native_app_window/README2
-rw-r--r--extensions/components/native_app_window/native_app_window_views.cc447
-rw-r--r--extensions/components/native_app_window/native_app_window_views.h197
11 files changed, 738 insertions, 0 deletions
diff --git a/extensions/DEPS b/extensions/DEPS
index 2286ed4..d2bbec8 100644
--- a/extensions/DEPS
+++ b/extensions/DEPS
@@ -7,6 +7,7 @@ include_rules = [
"+content/public/common",
"+content/public/test",
"+crypto",
+ "-extensions/components",
"+extensions/test",
"+grit/extensions_renderer_resources.h",
"+grit/extensions_resources.h",
diff --git a/extensions/components/DEPS b/extensions/components/DEPS
new file mode 100644
index 0000000..0a33fe4
--- /dev/null
+++ b/extensions/components/DEPS
@@ -0,0 +1,7 @@
+include_rules = [
+ # Things in extensions/components can depend on extensions, but not other
+ # extensions/components in a way that could make a cycle in the dependency
+ # graph. Individual components must explicitly declare their dependencies
+ # on other components.
+ "-extensions/components",
+]
diff --git a/extensions/components/README b/extensions/components/README
new file mode 100644
index 0000000..4f0474d
--- /dev/null
+++ b/extensions/components/README
@@ -0,0 +1,11 @@
+This directory holds components reused in multiple embedders which themselves
+have extensions dependencies. Components such as these do not belong in the root
+src/components, because src/extensions already depends on src/components. A
+component in src/components can not have an extensions dependency.
+
+Code in an extensions/component should be placed in a namespace corresponding to
+the name of the component (ignoring extensions); e.g. for a component living in
+extensions/components/foo, code in that component should be in the foo::
+namespace.
+
+See src/components/README for additional notes.
diff --git a/extensions/components/extensions_components.gyp b/extensions/components/extensions_components.gyp
new file mode 100644
index 0000000..953a2e1
--- /dev/null
+++ b/extensions/components/extensions_components.gyp
@@ -0,0 +1,19 @@
+# Copyright 2014 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.
+
+{
+ 'variables': {
+ # This turns on e.g. the filename-based detection of which
+ # platforms to include source files on (e.g. files ending in
+ # _mac.h or _mac.cc are only compiled on MacOSX).
+ 'chromium_code': 1,
+ },
+ 'conditions': [
+ ['toolkit_views==1', {
+ 'includes': [
+ 'native_app_window.gypi',
+ ],
+ }],
+ ],
+}
diff --git a/extensions/components/native_app_window.gypi b/extensions/components/native_app_window.gypi
new file mode 100644
index 0000000..5af1c92
--- /dev/null
+++ b/extensions/components/native_app_window.gypi
@@ -0,0 +1,27 @@
+# Copyright 2014 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.
+{
+ 'targets': [
+ {
+ 'target_name': 'native_app_window',
+ 'type': 'static_library',
+ 'dependencies': [
+ '../../base/base.gyp:base',
+ '../../content/content.gyp:content_browser',
+ '../../skia/skia.gyp:skia',
+ '../../ui/views/views.gyp:views',
+ '../../ui/views/controls/webview/webview.gyp:webview',
+ '../extensions.gyp:extensions_browser',
+ '../extensions.gyp:extensions_common',
+ ],
+ 'include_dirs': [
+ '../..',
+ ],
+ 'sources': [
+ 'native_app_window/native_app_window_views.cc',
+ 'native_app_window/native_app_window_views.h',
+ ],
+ },
+ ],
+}
diff --git a/extensions/components/native_app_window/BUILD.gn b/extensions/components/native_app_window/BUILD.gn
new file mode 100644
index 0000000..28330bc
--- /dev/null
+++ b/extensions/components/native_app_window/BUILD.gn
@@ -0,0 +1,20 @@
+# Copyright 2014 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.
+
+static_library("native_app_window") {
+ sources = [
+ "native_app_window_views.cc",
+ "native_app_window_views.h",
+ ]
+
+ deps = [
+ "//base",
+ "//skia",
+ "//ui/views",
+ "//ui/views/controls/webview",
+ "//content/public/browser",
+ "//extensions/browser",
+ "//extensions/common",
+ ]
+}
diff --git a/extensions/components/native_app_window/DEPS b/extensions/components/native_app_window/DEPS
new file mode 100644
index 0000000..aa37418
--- /dev/null
+++ b/extensions/components/native_app_window/DEPS
@@ -0,0 +1,4 @@
+include_rules = [
+ "+content/public/browser",
+ "+third_party/skia/include/core/SkRegion.h",
+]
diff --git a/extensions/components/native_app_window/OWNERS b/extensions/components/native_app_window/OWNERS
new file mode 100644
index 0000000..a3b54c9
--- /dev/null
+++ b/extensions/components/native_app_window/OWNERS
@@ -0,0 +1,3 @@
+benwells@chromium.org
+jackhou@chromium.org
+jamescook@chromium.org
diff --git a/extensions/components/native_app_window/README b/extensions/components/native_app_window/README
new file mode 100644
index 0000000..bec84bb
--- /dev/null
+++ b/extensions/components/native_app_window/README
@@ -0,0 +1,2 @@
+The native_app_window extensions component contains UI-specific implementations
+of extensions::NativeAppWindow.
diff --git a/extensions/components/native_app_window/native_app_window_views.cc b/extensions/components/native_app_window/native_app_window_views.cc
new file mode 100644
index 0000000..c460527
--- /dev/null
+++ b/extensions/components/native_app_window/native_app_window_views.cc
@@ -0,0 +1,447 @@
+// Copyright 2014 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 "extensions/components/native_app_window/native_app_window_views.h"
+
+#include "base/threading/sequenced_worker_pool.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/render_widget_host_view.h"
+#include "content/public/browser/web_contents.h"
+#include "extensions/browser/app_window/app_window.h"
+#include "extensions/common/draggable_region.h"
+#include "third_party/skia/include/core/SkRegion.h"
+#include "ui/gfx/path.h"
+#include "ui/views/controls/webview/webview.h"
+#include "ui/views/widget/widget.h"
+#include "ui/views/window/non_client_view.h"
+
+#if defined(USE_AURA)
+#include "ui/aura/window.h"
+#endif
+
+using extensions::AppWindow;
+
+namespace native_app_window {
+
+NativeAppWindowViews::NativeAppWindowViews()
+ : app_window_(NULL),
+ web_view_(NULL),
+ widget_(NULL),
+ frameless_(false),
+ resizable_(false) {
+}
+
+void NativeAppWindowViews::Init(AppWindow* app_window,
+ const AppWindow::CreateParams& create_params) {
+ app_window_ = app_window;
+ frameless_ = create_params.frame == AppWindow::FRAME_NONE;
+ resizable_ = create_params.resizable;
+ size_constraints_.set_minimum_size(
+ create_params.GetContentMinimumSize(gfx::Insets()));
+ size_constraints_.set_maximum_size(
+ create_params.GetContentMaximumSize(gfx::Insets()));
+ Observe(app_window_->web_contents());
+
+ widget_ = new views::Widget;
+ InitializeWindow(app_window, create_params);
+
+ OnViewWasResized();
+ widget_->AddObserver(this);
+}
+
+NativeAppWindowViews::~NativeAppWindowViews() {
+ web_view_->SetWebContents(NULL);
+}
+
+void NativeAppWindowViews::OnCanHaveAlphaEnabledChanged() {
+ app_window_->OnNativeWindowChanged();
+}
+
+void NativeAppWindowViews::InitializeWindow(
+ AppWindow* app_window,
+ const AppWindow::CreateParams& create_params) {
+ // Stub implementation. See also ChromeNativeAppWindowViews.
+ views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_WINDOW);
+ init_params.delegate = this;
+ init_params.keep_on_top = create_params.always_on_top;
+ widget_->Init(init_params);
+ widget_->CenterWindow(
+ create_params.GetInitialWindowBounds(gfx::Insets()).size());
+}
+
+// ui::BaseWindow implementation.
+
+bool NativeAppWindowViews::IsActive() const {
+ return widget_->IsActive();
+}
+
+bool NativeAppWindowViews::IsMaximized() const {
+ return widget_->IsMaximized();
+}
+
+bool NativeAppWindowViews::IsMinimized() const {
+ return widget_->IsMinimized();
+}
+
+bool NativeAppWindowViews::IsFullscreen() const {
+ return widget_->IsFullscreen();
+}
+
+gfx::NativeWindow NativeAppWindowViews::GetNativeWindow() {
+ return widget_->GetNativeWindow();
+}
+
+gfx::Rect NativeAppWindowViews::GetRestoredBounds() const {
+ return widget_->GetRestoredBounds();
+}
+
+ui::WindowShowState NativeAppWindowViews::GetRestoredState() const {
+ // Stub implementation. See also ChromeNativeAppWindowViews.
+ if (IsMaximized())
+ return ui::SHOW_STATE_MAXIMIZED;
+ if (IsFullscreen())
+ return ui::SHOW_STATE_FULLSCREEN;
+ return ui::SHOW_STATE_NORMAL;
+}
+
+gfx::Rect NativeAppWindowViews::GetBounds() const {
+ return widget_->GetWindowBoundsInScreen();
+}
+
+void NativeAppWindowViews::Show() {
+ if (widget_->IsVisible()) {
+ widget_->Activate();
+ return;
+ }
+ widget_->Show();
+}
+
+void NativeAppWindowViews::ShowInactive() {
+ if (widget_->IsVisible())
+ return;
+
+ widget_->ShowInactive();
+}
+
+void NativeAppWindowViews::Hide() {
+ widget_->Hide();
+}
+
+void NativeAppWindowViews::Close() {
+ widget_->Close();
+}
+
+void NativeAppWindowViews::Activate() {
+ widget_->Activate();
+}
+
+void NativeAppWindowViews::Deactivate() {
+ widget_->Deactivate();
+}
+
+void NativeAppWindowViews::Maximize() {
+ widget_->Maximize();
+}
+
+void NativeAppWindowViews::Minimize() {
+ widget_->Minimize();
+}
+
+void NativeAppWindowViews::Restore() {
+ widget_->Restore();
+}
+
+void NativeAppWindowViews::SetBounds(const gfx::Rect& bounds) {
+ widget_->SetBounds(bounds);
+}
+
+void NativeAppWindowViews::FlashFrame(bool flash) {
+ widget_->FlashFrame(flash);
+}
+
+bool NativeAppWindowViews::IsAlwaysOnTop() const {
+ // Stub implementation. See also ChromeNativeAppWindowViews.
+ return widget_->IsAlwaysOnTop();
+}
+
+void NativeAppWindowViews::SetAlwaysOnTop(bool always_on_top) {
+ widget_->SetAlwaysOnTop(always_on_top);
+}
+
+gfx::NativeView NativeAppWindowViews::GetHostView() const {
+ return widget_->GetNativeView();
+}
+
+gfx::Point NativeAppWindowViews::GetDialogPosition(const gfx::Size& size) {
+ gfx::Size app_window_size = widget_->GetWindowBoundsInScreen().size();
+ return gfx::Point(app_window_size.width() / 2 - size.width() / 2,
+ app_window_size.height() / 2 - size.height() / 2);
+}
+
+gfx::Size NativeAppWindowViews::GetMaximumDialogSize() {
+ return widget_->GetWindowBoundsInScreen().size();
+}
+
+void NativeAppWindowViews::AddObserver(
+ web_modal::ModalDialogHostObserver* observer) {
+ observer_list_.AddObserver(observer);
+}
+void NativeAppWindowViews::RemoveObserver(
+ web_modal::ModalDialogHostObserver* observer) {
+ observer_list_.RemoveObserver(observer);
+}
+
+void NativeAppWindowViews::OnViewWasResized() {
+ FOR_EACH_OBSERVER(web_modal::ModalDialogHostObserver,
+ observer_list_,
+ OnPositionRequiresUpdate());
+}
+
+// WidgetDelegate implementation.
+
+void NativeAppWindowViews::OnWidgetMove() {
+ app_window_->OnNativeWindowChanged();
+}
+
+views::View* NativeAppWindowViews::GetInitiallyFocusedView() {
+ return web_view_;
+}
+
+bool NativeAppWindowViews::CanResize() const {
+ return resizable_ && !size_constraints_.HasFixedSize() &&
+ !WidgetHasHitTestMask();
+}
+
+bool NativeAppWindowViews::CanMaximize() const {
+ return resizable_ && !size_constraints_.HasMaximumSize() &&
+ !app_window_->window_type_is_panel() && !WidgetHasHitTestMask();
+}
+
+bool NativeAppWindowViews::CanMinimize() const {
+ return true;
+}
+
+base::string16 NativeAppWindowViews::GetWindowTitle() const {
+ return app_window_->GetTitle();
+}
+
+bool NativeAppWindowViews::ShouldShowWindowTitle() const {
+ return app_window_->window_type() == AppWindow::WINDOW_TYPE_V1_PANEL;
+}
+
+bool NativeAppWindowViews::ShouldShowWindowIcon() const {
+ return app_window_->window_type() == AppWindow::WINDOW_TYPE_V1_PANEL;
+}
+
+void NativeAppWindowViews::SaveWindowPlacement(const gfx::Rect& bounds,
+ ui::WindowShowState show_state) {
+ views::WidgetDelegate::SaveWindowPlacement(bounds, show_state);
+ app_window_->OnNativeWindowChanged();
+}
+
+void NativeAppWindowViews::DeleteDelegate() {
+ widget_->RemoveObserver(this);
+ app_window_->OnNativeClose();
+}
+
+views::Widget* NativeAppWindowViews::GetWidget() {
+ return widget_;
+}
+
+const views::Widget* NativeAppWindowViews::GetWidget() const {
+ return widget_;
+}
+
+views::View* NativeAppWindowViews::GetContentsView() {
+ return this;
+}
+
+bool NativeAppWindowViews::ShouldDescendIntoChildForEventHandling(
+ gfx::NativeView child,
+ const gfx::Point& location) {
+#if defined(USE_AURA)
+ if (child->Contains(web_view_->web_contents()->GetNativeView())) {
+ // App window should claim mouse events that fall within the draggable
+ // region.
+ return !draggable_region_.get() ||
+ !draggable_region_->contains(location.x(), location.y());
+ }
+#endif
+
+ return true;
+}
+
+// WidgetObserver implementation.
+
+void NativeAppWindowViews::OnWidgetVisibilityChanged(views::Widget* widget,
+ bool visible) {
+ app_window_->OnNativeWindowChanged();
+}
+
+void NativeAppWindowViews::OnWidgetActivationChanged(views::Widget* widget,
+ bool active) {
+ app_window_->OnNativeWindowChanged();
+ if (active)
+ app_window_->OnNativeWindowActivated();
+}
+
+// WebContentsObserver implementation.
+
+void NativeAppWindowViews::RenderViewCreated(
+ content::RenderViewHost* render_view_host) {
+ if (app_window_->requested_alpha_enabled() && CanHaveAlphaEnabled()) {
+ content::RenderWidgetHostView* view = render_view_host->GetView();
+ DCHECK(view);
+ view->SetBackgroundOpaque(false);
+ }
+}
+
+void NativeAppWindowViews::RenderViewHostChanged(
+ content::RenderViewHost* old_host,
+ content::RenderViewHost* new_host) {
+ OnViewWasResized();
+}
+
+// views::View implementation.
+
+void NativeAppWindowViews::Layout() {
+ DCHECK(web_view_);
+ web_view_->SetBounds(0, 0, width(), height());
+ OnViewWasResized();
+}
+
+void NativeAppWindowViews::ViewHierarchyChanged(
+ const ViewHierarchyChangedDetails& details) {
+ if (details.is_add && details.child == this) {
+ web_view_ = new views::WebView(NULL);
+ AddChildView(web_view_);
+ web_view_->SetWebContents(app_window_->web_contents());
+ }
+}
+
+gfx::Size NativeAppWindowViews::GetMinimumSize() const {
+ return size_constraints_.GetMinimumSize();
+}
+
+gfx::Size NativeAppWindowViews::GetMaximumSize() const {
+ return size_constraints_.GetMaximumSize();
+}
+
+void NativeAppWindowViews::OnFocus() {
+ web_view_->RequestFocus();
+}
+
+// NativeAppWindow implementation.
+
+void NativeAppWindowViews::SetFullscreen(int fullscreen_types) {
+ // Stub implementation. See also ChromeNativeAppWindowViews.
+ widget_->SetFullscreen(fullscreen_types != AppWindow::FULLSCREEN_TYPE_NONE);
+}
+
+bool NativeAppWindowViews::IsFullscreenOrPending() const {
+ // Stub implementation. See also ChromeNativeAppWindowViews.
+ return widget_->IsFullscreen();
+}
+
+void NativeAppWindowViews::UpdateWindowIcon() {
+ widget_->UpdateWindowIcon();
+}
+
+void NativeAppWindowViews::UpdateWindowTitle() {
+ widget_->UpdateWindowTitle();
+}
+
+void NativeAppWindowViews::UpdateBadgeIcon() {
+ // Stub implementation. See also ChromeNativeAppWindowViews.
+}
+
+void NativeAppWindowViews::UpdateDraggableRegions(
+ const std::vector<extensions::DraggableRegion>& regions) {
+ // Draggable region is not supported for non-frameless window.
+ if (!frameless_)
+ return;
+
+ draggable_region_.reset(AppWindow::RawDraggableRegionsToSkRegion(regions));
+ OnViewWasResized();
+}
+
+SkRegion* NativeAppWindowViews::GetDraggableRegion() {
+ return draggable_region_.get();
+}
+
+void NativeAppWindowViews::UpdateShape(scoped_ptr<SkRegion> region) {
+ // Stub implementation. See also ChromeNativeAppWindowViews.
+}
+
+void NativeAppWindowViews::HandleKeyboardEvent(
+ const content::NativeWebKeyboardEvent& event) {
+ unhandled_keyboard_event_handler_.HandleKeyboardEvent(event,
+ GetFocusManager());
+}
+
+bool NativeAppWindowViews::IsFrameless() const {
+ return frameless_;
+}
+
+bool NativeAppWindowViews::HasFrameColor() const {
+ return false;
+}
+
+SkColor NativeAppWindowViews::ActiveFrameColor() const {
+ return SK_ColorBLACK;
+}
+
+SkColor NativeAppWindowViews::InactiveFrameColor() const {
+ return SK_ColorBLACK;
+}
+
+gfx::Insets NativeAppWindowViews::GetFrameInsets() const {
+ if (frameless_)
+ return gfx::Insets();
+
+ // The pretend client_bounds passed in need to be large enough to ensure that
+ // GetWindowBoundsForClientBounds() doesn't decide that it needs more than
+ // the specified amount of space to fit the window controls in, and return a
+ // number larger than the real frame insets. Most window controls are smaller
+ // than 1000x1000px, so this should be big enough.
+ gfx::Rect client_bounds = gfx::Rect(1000, 1000);
+ gfx::Rect window_bounds =
+ widget_->non_client_view()->GetWindowBoundsForClientBounds(client_bounds);
+ return window_bounds.InsetsFrom(client_bounds);
+}
+
+void NativeAppWindowViews::HideWithApp() {
+}
+
+void NativeAppWindowViews::ShowWithApp() {
+}
+
+void NativeAppWindowViews::UpdateShelfMenu() {
+}
+
+gfx::Size NativeAppWindowViews::GetContentMinimumSize() const {
+ return size_constraints_.GetMinimumSize();
+}
+
+gfx::Size NativeAppWindowViews::GetContentMaximumSize() const {
+ return size_constraints_.GetMaximumSize();
+}
+
+void NativeAppWindowViews::SetContentSizeConstraints(
+ const gfx::Size& min_size,
+ const gfx::Size& max_size) {
+ size_constraints_.set_minimum_size(min_size);
+ size_constraints_.set_maximum_size(max_size);
+ widget_->OnSizeConstraintsChanged();
+}
+
+bool NativeAppWindowViews::CanHaveAlphaEnabled() const {
+ return widget_->IsTranslucentWindowOpacitySupported();
+}
+
+void NativeAppWindowViews::SetVisibleOnAllWorkspaces(bool always_visible) {
+ widget_->SetVisibleOnAllWorkspaces(always_visible);
+}
+
+} // namespace native_app_window
diff --git a/extensions/components/native_app_window/native_app_window_views.h b/extensions/components/native_app_window/native_app_window_views.h
new file mode 100644
index 0000000..aabf4bb
--- /dev/null
+++ b/extensions/components/native_app_window/native_app_window_views.h
@@ -0,0 +1,197 @@
+// Copyright 2014 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.
+
+#ifndef EXTENSIONS_COMPONENTS_NATIVE_APP_WINDOW_NATIVE_APP_WINDOW_VIEWS_H_
+#define EXTENSIONS_COMPONENTS_NATIVE_APP_WINDOW_NATIVE_APP_WINDOW_VIEWS_H_
+
+#include "base/observer_list.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "extensions/browser/app_window/app_window.h"
+#include "extensions/browser/app_window/native_app_window.h"
+#include "extensions/browser/app_window/size_constraints.h"
+#include "ui/gfx/rect.h"
+#include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
+#include "ui/views/widget/widget.h"
+#include "ui/views/widget/widget_delegate.h"
+#include "ui/views/widget/widget_observer.h"
+
+class SkRegion;
+
+namespace content {
+class BrowserContext;
+class RenderViewHost;
+class WebContents;
+}
+
+namespace extensions {
+class Extension;
+}
+
+namespace ui {
+class MenuModel;
+}
+
+namespace views {
+class MenuRunner;
+class WebView;
+}
+
+namespace native_app_window {
+
+// A NativeAppWindow backed by a views::Widget. This class may be used alone
+// as a stub or subclassed (for example, ChromeNativeAppWindowViews).
+class NativeAppWindowViews : public extensions::NativeAppWindow,
+ public content::WebContentsObserver,
+ public views::WidgetDelegateView,
+ public views::WidgetObserver {
+ public:
+ NativeAppWindowViews();
+ virtual ~NativeAppWindowViews();
+ void Init(extensions::AppWindow* app_window,
+ const extensions::AppWindow::CreateParams& create_params);
+
+ // Signal that CanHaveTransparentBackground has changed.
+ void OnCanHaveAlphaEnabledChanged();
+
+ views::Widget* widget() { return widget_; }
+
+ void set_window_for_testing(views::Widget* window) { widget_ = window; }
+ void set_web_view_for_testing(views::WebView* view) { web_view_ = view; }
+
+ protected:
+ extensions::AppWindow* app_window() { return app_window_; }
+ const extensions::AppWindow* app_window() const { return app_window_; }
+
+ const views::Widget* widget() const { return widget_; }
+
+ views::WebView* web_view() { return web_view_; }
+
+ // Initializes |widget_| for |app_window|.
+ virtual void InitializeWindow(
+ extensions::AppWindow* app_window,
+ const extensions::AppWindow::CreateParams& create_params);
+
+ // ui::BaseWindow implementation.
+ virtual bool IsActive() const OVERRIDE;
+ virtual bool IsMaximized() const OVERRIDE;
+ virtual bool IsMinimized() const OVERRIDE;
+ virtual bool IsFullscreen() const OVERRIDE;
+ virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
+ virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
+ virtual ui::WindowShowState GetRestoredState() const OVERRIDE;
+ virtual gfx::Rect GetBounds() const OVERRIDE;
+ virtual void Show() OVERRIDE;
+ virtual void ShowInactive() OVERRIDE;
+ virtual void Hide() OVERRIDE;
+ virtual void Close() OVERRIDE;
+ virtual void Activate() OVERRIDE;
+ virtual void Deactivate() OVERRIDE;
+ virtual void Maximize() OVERRIDE;
+ virtual void Minimize() OVERRIDE;
+ virtual void Restore() OVERRIDE;
+ virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
+ virtual void FlashFrame(bool flash) OVERRIDE;
+ virtual bool IsAlwaysOnTop() const OVERRIDE;
+ virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE;
+
+ // WidgetDelegate implementation.
+ virtual void OnWidgetMove() OVERRIDE;
+ virtual views::View* GetInitiallyFocusedView() OVERRIDE;
+ virtual bool CanResize() const OVERRIDE;
+ virtual bool CanMaximize() const OVERRIDE;
+ virtual bool CanMinimize() const OVERRIDE;
+ virtual base::string16 GetWindowTitle() const OVERRIDE;
+ virtual bool ShouldShowWindowTitle() const OVERRIDE;
+ virtual bool ShouldShowWindowIcon() const OVERRIDE;
+ virtual void SaveWindowPlacement(const gfx::Rect& bounds,
+ ui::WindowShowState show_state) OVERRIDE;
+ virtual void DeleteDelegate() OVERRIDE;
+ virtual views::Widget* GetWidget() OVERRIDE;
+ virtual const views::Widget* GetWidget() const OVERRIDE;
+ virtual views::View* GetContentsView() OVERRIDE;
+ virtual bool ShouldDescendIntoChildForEventHandling(
+ gfx::NativeView child,
+ const gfx::Point& location) OVERRIDE;
+
+ // WidgetObserver implementation.
+ virtual void OnWidgetVisibilityChanged(views::Widget* widget,
+ bool visible) OVERRIDE;
+ virtual void OnWidgetActivationChanged(views::Widget* widget,
+ bool active) OVERRIDE;
+
+ // WebContentsObserver implementation.
+ virtual void RenderViewCreated(
+ content::RenderViewHost* render_view_host) OVERRIDE;
+ virtual void RenderViewHostChanged(
+ content::RenderViewHost* old_host,
+ content::RenderViewHost* new_host) OVERRIDE;
+
+ // views::View implementation.
+ virtual void Layout() OVERRIDE;
+ virtual void ViewHierarchyChanged(
+ const ViewHierarchyChangedDetails& details) OVERRIDE;
+ virtual gfx::Size GetMinimumSize() const OVERRIDE;
+ virtual gfx::Size GetMaximumSize() const OVERRIDE;
+ virtual void OnFocus() OVERRIDE;
+
+ // NativeAppWindow implementation.
+ virtual void SetFullscreen(int fullscreen_types) OVERRIDE;
+ virtual bool IsFullscreenOrPending() const OVERRIDE;
+ virtual void UpdateWindowIcon() OVERRIDE;
+ virtual void UpdateWindowTitle() OVERRIDE;
+ virtual void UpdateBadgeIcon() OVERRIDE;
+ virtual void UpdateDraggableRegions(
+ const std::vector<extensions::DraggableRegion>& regions) OVERRIDE;
+ virtual SkRegion* GetDraggableRegion() OVERRIDE;
+ virtual void UpdateShape(scoped_ptr<SkRegion> region) OVERRIDE;
+ virtual void HandleKeyboardEvent(
+ const content::NativeWebKeyboardEvent& event) OVERRIDE;
+ virtual bool IsFrameless() const OVERRIDE;
+ virtual bool HasFrameColor() const OVERRIDE;
+ virtual SkColor ActiveFrameColor() const OVERRIDE;
+ virtual SkColor InactiveFrameColor() const OVERRIDE;
+ virtual gfx::Insets GetFrameInsets() const OVERRIDE;
+ virtual void HideWithApp() OVERRIDE;
+ virtual void ShowWithApp() OVERRIDE;
+ virtual void UpdateShelfMenu() OVERRIDE;
+ virtual gfx::Size GetContentMinimumSize() const OVERRIDE;
+ virtual gfx::Size GetContentMaximumSize() const OVERRIDE;
+ virtual void SetContentSizeConstraints(const gfx::Size& min_size,
+ const gfx::Size& max_size) OVERRIDE;
+ virtual bool CanHaveAlphaEnabled() const OVERRIDE;
+ virtual void SetVisibleOnAllWorkspaces(bool always_visible) OVERRIDE;
+
+ // web_modal::WebContentsModalDialogHost implementation.
+ virtual gfx::NativeView GetHostView() const OVERRIDE;
+ virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE;
+ virtual gfx::Size GetMaximumDialogSize() OVERRIDE;
+ virtual void AddObserver(
+ web_modal::ModalDialogHostObserver* observer) OVERRIDE;
+ virtual void RemoveObserver(
+ web_modal::ModalDialogHostObserver* observer) OVERRIDE;
+
+ private:
+ // Informs modal dialogs that they need to update their positions.
+ void OnViewWasResized();
+
+ extensions::AppWindow* app_window_; // Not owned.
+ views::WebView* web_view_;
+ views::Widget* widget_;
+
+ scoped_ptr<SkRegion> draggable_region_;
+
+ bool frameless_;
+ bool resizable_;
+ extensions::SizeConstraints size_constraints_;
+
+ views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
+
+ ObserverList<web_modal::ModalDialogHostObserver> observer_list_;
+
+ DISALLOW_COPY_AND_ASSIGN(NativeAppWindowViews);
+};
+
+} // namespace native_app_window
+
+#endif // EXTENSIONS_COMPONENTS_NATIVE_APP_WINDOW_NATIVE_APP_WINDOW_VIEWS_H_