Index: chrome/browser/ui/views/extensions/app_base_window_views.cc |
diff --git a/chrome/browser/ui/views/extensions/app_base_window_views.cc b/chrome/browser/ui/views/extensions/app_base_window_views.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..511e239bc2ce325e43604dde76e21afb2db4d0ed |
--- /dev/null |
+++ b/chrome/browser/ui/views/extensions/app_base_window_views.cc |
@@ -0,0 +1,302 @@ |
+// Copyright (c) 2012 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 "chrome/browser/ui/views/extensions/app_base_window_views.h" |
+ |
+#include "chrome/browser/extensions/extension_host.h" |
+#include "chrome/browser/favicon/favicon_tab_helper.h" |
+#include "chrome/browser/ui/views/extensions/app_window_views.h" |
+#include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views.h" |
+#include "chrome/common/extensions/draggable_region.h" |
+#include "chrome/common/extensions/extension.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 "content/public/browser/web_contents_view.h" |
+#include "ui/views/controls/webview/webview.h" |
+#include "ui/views/widget/widget.h" |
+#include "ui/views/window/non_client_view.h" |
+ |
+AppBaseWindowViews::AppBaseWindowViews( |
+ ShellWindow* shell_window, |
+ const ShellWindow::CreateParams& win_params) |
+ : shell_window_(shell_window), |
+ web_view_(NULL), |
+ window_(NULL), |
+ is_fullscreen_(false), |
+ frameless_(win_params.frame == ShellWindow::CreateParams::FRAME_NONE) { |
+ minimum_size_ = win_params.minimum_size; |
+ maximum_size_ = win_params.maximum_size; |
+} |
+ |
+AppBaseWindowViews::~AppBaseWindowViews() { |
+ web_view_->SetWebContents(NULL); |
+} |
+ |
+void AppBaseWindowViews::Initialize( |
+ const ShellWindow::CreateParams& params) { |
+ window_ = new views::Widget; |
+ InitializeWindow(params.bounds); |
+ extension_keybinding_registry_.reset( |
+ new ExtensionKeybindingRegistryViews( |
+ profile(), |
+ window()->GetFocusManager(), |
+ extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, |
+ shell_window())); |
+ OnViewWasResized(); |
+} |
+ |
+// BaseWindow implementation. |
+ |
+bool AppBaseWindowViews::IsActive() const { |
+ return window_->IsActive(); |
+} |
+ |
+bool AppBaseWindowViews::IsMaximized() const { |
+ return window_->IsMaximized(); |
+} |
+ |
+bool AppBaseWindowViews::IsMinimized() const { |
+ return window_->IsMinimized(); |
+} |
+ |
+bool AppBaseWindowViews::IsFullscreen() const { |
+ return window_->IsFullscreen(); |
+} |
+ |
+gfx::NativeWindow AppBaseWindowViews::GetNativeWindow() { |
+ return window_->GetNativeWindow(); |
+} |
+ |
+gfx::Rect AppBaseWindowViews::GetRestoredBounds() const { |
+ return window_->GetRestoredBounds(); |
+} |
+ |
+gfx::Rect AppBaseWindowViews::GetBounds() const { |
+ return window_->GetWindowBoundsInScreen(); |
+} |
+ |
+void AppBaseWindowViews::Show() { |
+ if (window_->IsVisible()) { |
+ window_->Activate(); |
+ return; |
+ } |
+ |
+ window_->Show(); |
+} |
+ |
+void AppBaseWindowViews::ShowInactive() { |
+ if (window_->IsVisible()) |
+ return; |
+ window_->ShowInactive(); |
+} |
+ |
+void AppBaseWindowViews::Hide() { |
+ window_->Hide(); |
+} |
+ |
+void AppBaseWindowViews::Close() { |
+ window_->Close(); |
+} |
+ |
+void AppBaseWindowViews::Activate() { |
+ window_->Activate(); |
+} |
+ |
+void AppBaseWindowViews::Deactivate() { |
+ window_->Deactivate(); |
+} |
+ |
+void AppBaseWindowViews::Maximize() { |
+ window_->Maximize(); |
+} |
+ |
+void AppBaseWindowViews::Minimize() { |
+ window_->Minimize(); |
+} |
+ |
+void AppBaseWindowViews::Restore() { |
+ window_->Restore(); |
+} |
+ |
+void AppBaseWindowViews::SetBounds(const gfx::Rect& bounds) { |
+ GetWidget()->SetBounds(bounds); |
+} |
+ |
+void AppBaseWindowViews::FlashFrame(bool flash) { |
+ window_->FlashFrame(flash); |
+} |
+ |
+bool AppBaseWindowViews::IsAlwaysOnTop() const { |
+ return false; |
+} |
+ |
+// WidgetDelegate implementation. |
+ |
+views::View* AppBaseWindowViews::GetContentsView() { |
+ return this; |
+} |
+ |
+bool AppBaseWindowViews::CanResize() const { |
+ return maximum_size_.IsEmpty() || minimum_size_ != maximum_size_; |
+} |
+ |
+bool AppBaseWindowViews::CanMaximize() const { |
+ return CanResize(); |
+} |
+ |
+views::Widget* AppBaseWindowViews::GetWidget() { |
+ return window_; |
+} |
+ |
+const views::Widget* AppBaseWindowViews::GetWidget() const { |
+ return window_; |
+} |
+ |
+string16 AppBaseWindowViews::GetWindowTitle() const { |
+ return shell_window_->GetTitle(); |
+} |
+ |
+void AppBaseWindowViews::DeleteDelegate() { |
+ shell_window_->OnNativeClose(); |
+} |
+ |
+views::View* AppBaseWindowViews::GetInitiallyFocusedView() { |
+ return web_view_; |
+} |
+ |
+bool AppBaseWindowViews::ShouldDescendIntoChildForEventHandling( |
+ gfx::NativeView child, |
+ const gfx::Point& location) { |
+#if defined(USE_AURA) |
+ DCHECK_EQ(child, web_view_->web_contents()->GetView()->GetNativeView()); |
+ // Shell window should claim mouse events that fall within the draggable |
+ // region. |
+ return !draggable_region_.get() || |
+ !draggable_region_->contains(location.x(), location.y()); |
+#else |
+ return true; |
+#endif |
+} |
+ |
+gfx::ImageSkia AppBaseWindowViews::GetWindowAppIcon() { |
+ gfx::Image app_icon = shell_window_->app_icon(); |
+ if (app_icon.IsEmpty()) |
+ return GetWindowIcon(); |
+ else |
+ return *app_icon.ToImageSkia(); |
+} |
+ |
+gfx::ImageSkia AppBaseWindowViews::GetWindowIcon() { |
+ content::WebContents* web_contents = shell_window_->web_contents(); |
+ if (web_contents) { |
+ FaviconTabHelper* favicon_tab_helper = |
+ FaviconTabHelper::FromWebContents(web_contents); |
+ gfx::Image app_icon = favicon_tab_helper->GetFavicon(); |
+ if (!app_icon.IsEmpty()) |
+ return *app_icon.ToImageSkia(); |
+ } |
+ return gfx::ImageSkia(); |
+} |
+ |
+bool AppBaseWindowViews::ShouldShowWindowTitle() const { |
+ return false; |
+} |
+ |
+void AppBaseWindowViews::OnWidgetMove() { |
+ shell_window_->SaveWindowPosition(); |
+} |
+ |
+// Protected methods. |
+ |
+void AppBaseWindowViews::OnViewWasResized() { |
+} |
+ |
+// views::View implementation. |
+ |
+void AppBaseWindowViews::Layout() { |
+ DCHECK(web_view_); |
+ web_view_->SetBounds(0, 0, width(), height()); |
+ OnViewWasResized(); |
+} |
+ |
+void AppBaseWindowViews::ViewHierarchyChanged( |
+ bool is_add, views::View *parent, views::View *child) { |
+ if (is_add && child == this) { |
+ web_view_ = new views::WebView(NULL); |
+ AddChildView(web_view_); |
+ web_view_->SetWebContents(web_contents()); |
+ } |
+} |
+ |
+gfx::Size AppBaseWindowViews::GetMinimumSize() { |
+ return minimum_size_; |
+} |
+ |
+gfx::Size AppBaseWindowViews::GetMaximumSize() { |
+ return maximum_size_; |
+} |
+ |
+void AppBaseWindowViews::OnFocus() { |
+ web_view_->RequestFocus(); |
+} |
+ |
+void AppBaseWindowViews::SaveWindowPlacement( |
+ const gfx::Rect& bounds, |
+ ui::WindowShowState show_state) { |
+ views::WidgetDelegate::SaveWindowPlacement(bounds, show_state); |
+ shell_window_->SaveWindowPosition(); |
+} |
+ |
+// AppBaseWindow implementation. |
+ |
+void AppBaseWindowViews::SetFullscreen(bool fullscreen) { |
+ is_fullscreen_ = fullscreen; |
+ window_->SetFullscreen(fullscreen); |
+ // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we |
+ // ever drop the window out of fullscreen in response to something that |
+ // wasn't the app calling webkitCancelFullScreen(). |
+} |
+ |
+bool AppBaseWindowViews::IsFullscreenOrPending() const { |
+ return is_fullscreen_; |
+} |
+ |
+void AppBaseWindowViews::UpdateWindowIcon() { |
+ window_->UpdateWindowIcon(); |
+} |
+ |
+void AppBaseWindowViews::UpdateWindowTitle() { |
+ window_->UpdateWindowTitle(); |
+} |
+ |
+void AppBaseWindowViews::UpdateDraggableRegions( |
+ const std::vector<extensions::DraggableRegion>& regions) { |
+ // Draggable region is not supported for non-frameless window. |
+ if (!frameless_) |
+ return; |
+ |
+ draggable_region_.reset(ShellWindow::RawDraggableRegionsToSkRegion(regions)); |
+ OnViewWasResized(); |
+} |
+ |
+void AppBaseWindowViews::HandleKeyboardEvent( |
+ const content::NativeWebKeyboardEvent& event) { |
+ unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, |
+ GetFocusManager()); |
+} |
+ |
+void AppBaseWindowViews::RenderViewHostChanged() { |
+ OnViewWasResized(); |
+} |
+ |
+//------------------------------------------------------------------------------ |
+ |
+// static |
+AppBaseWindow* AppBaseWindow::Create( |
+ ShellWindow* shell_window, const ShellWindow::CreateParams& params) { |
+ AppBaseWindowViews* window = new AppWindowViews(shell_window, params); |
+ window->Initialize(params); |
+ return window; |
+} |