| Index: chrome/browser/ui/views/extensions/app_window_views.cc
|
| diff --git a/chrome/browser/ui/views/extensions/shell_window_views.cc b/chrome/browser/ui/views/extensions/app_window_views.cc
|
| similarity index 68%
|
| rename from chrome/browser/ui/views/extensions/shell_window_views.cc
|
| rename to chrome/browser/ui/views/extensions/app_window_views.cc
|
| index c8e0ec94e6e31255d465a6e1f602464f6653b801..ffff70b88f204c1484365adb69c95ab17cd1c913 100644
|
| --- a/chrome/browser/ui/views/extensions/shell_window_views.cc
|
| +++ b/chrome/browser/ui/views/extensions/app_window_views.cc
|
| @@ -2,18 +2,10 @@
|
| // 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/shell_window_views.h"
|
| +#include "chrome/browser/ui/views/extensions/app_window_views.h"
|
|
|
| -#include "base/utf_string_conversions.h"
|
| -#include "chrome/browser/extensions/extension_host.h"
|
| -#include "chrome/browser/favicon/favicon_tab_helper.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 "grit/theme_resources.h"
|
| #include "grit/ui_strings.h" // Accessibility names
|
| #include "third_party/skia/include/core/SkPaint.h"
|
| @@ -21,19 +13,17 @@
|
| #include "ui/base/l10n/l10n_util.h"
|
| #include "ui/base/resource/resource_bundle.h"
|
| #include "ui/gfx/canvas.h"
|
| -#include "ui/gfx/image/image.h"
|
| #include "ui/gfx/path.h"
|
| -#include "ui/views/controls/button/button.h"
|
| #include "ui/views/controls/button/image_button.h"
|
| #include "ui/views/controls/webview/webview.h"
|
| -#include "ui/views/layout/grid_layout.h"
|
| -#include "ui/views/views_delegate.h"
|
| #include "ui/views/widget/widget.h"
|
| -#include "ui/views/window/non_client_view.h"
|
|
|
| #if defined(OS_WIN) && !defined(USE_AURA)
|
| +#include "base/utf_string_conversions.h"
|
| #include "chrome/browser/shell_integration.h"
|
| #include "chrome/browser/web_applications/web_app.h"
|
| +#include "content/public/browser/render_view_host.h"
|
| +#include "content/public/browser/render_widget_host_view.h"
|
| #include "ui/base/win/shell.h"
|
| #endif
|
|
|
| @@ -46,19 +36,18 @@
|
| #endif
|
|
|
| namespace {
|
| +
|
| const int kResizeInsideBoundsSize = 5;
|
| const int kResizeAreaCornerSize = 16;
|
| -
|
| // Height of the chrome-style caption, in pixels.
|
| const int kCaptionHeight = 25;
|
| -} // namespace
|
|
|
| class ShellWindowFrameView : public views::NonClientFrameView,
|
| public views::ButtonListener {
|
| public:
|
| static const char kViewClassName[];
|
|
|
| - explicit ShellWindowFrameView(ShellWindowViews* window);
|
| + explicit ShellWindowFrameView(AppWindowViews* window);
|
| virtual ~ShellWindowFrameView();
|
|
|
| void Init(views::Widget* frame);
|
| @@ -87,7 +76,7 @@ class ShellWindowFrameView : public views::NonClientFrameView,
|
| virtual void ButtonPressed(views::Button* sender, const ui::Event& event)
|
| OVERRIDE;
|
|
|
| - ShellWindowViews* window_;
|
| + AppWindowViews* window_;
|
| views::Widget* frame_;
|
| views::ImageButton* close_button_;
|
| views::ImageButton* maximize_button_;
|
| @@ -100,7 +89,7 @@ class ShellWindowFrameView : public views::NonClientFrameView,
|
| const char ShellWindowFrameView::kViewClassName[] =
|
| "browser/ui/views/extensions/ShellWindowFrameView";
|
|
|
| -ShellWindowFrameView::ShellWindowFrameView(ShellWindowViews* window)
|
| +ShellWindowFrameView::ShellWindowFrameView(AppWindowViews* window)
|
| : window_(window),
|
| frame_(NULL),
|
| close_button_(NULL) {
|
| @@ -395,243 +384,76 @@ void ShellWindowFrameView::ButtonPressed(views::Button* sender,
|
| frame_->Minimize();
|
| }
|
|
|
| -ShellWindowViews::ShellWindowViews(ShellWindow* shell_window,
|
| - const ShellWindow::CreateParams& win_params)
|
| - : shell_window_(shell_window),
|
| - web_view_(NULL),
|
| - is_fullscreen_(false),
|
| - frameless_(win_params.frame == ShellWindow::CreateParams::FRAME_NONE) {
|
| - window_ = new views::Widget;
|
| +} // namespace
|
| +
|
| +//------------------------------------------------------------------------------
|
| +// AppWindowViews
|
| +
|
| +AppWindowViews::AppWindowViews(ShellWindow* shell_window,
|
| + const ShellWindow::CreateParams& win_params)
|
| + : AppBaseWindowViews(shell_window, win_params) {
|
| +}
|
| +
|
| +AppWindowViews::~AppWindowViews() {
|
| +}
|
| +
|
| +void AppWindowViews::InitializeWindow(const gfx::Rect& initial_bounds) {
|
| views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
|
| params.delegate = this;
|
| params.remove_standard_frame = true;
|
| params.use_system_default_icon = true;
|
| - minimum_size_ = win_params.minimum_size;
|
| - maximum_size_ = win_params.maximum_size;
|
| - window_->Init(params);
|
| + window()->Init(params);
|
| +
|
| gfx::Rect window_bounds =
|
| - window_->non_client_view()->GetWindowBoundsForClientBounds(
|
| - win_params.bounds);
|
| + window()->non_client_view()->GetWindowBoundsForClientBounds(
|
| + initial_bounds);
|
| // Center window if no position was specified.
|
| - if (win_params.bounds.x() == INT_MIN || win_params.bounds.y() == INT_MIN) {
|
| - window_->CenterWindow(window_bounds.size());
|
| + if (initial_bounds.x() == INT_MIN || initial_bounds.y() == INT_MIN) {
|
| + window()->CenterWindow(window_bounds.size());
|
| } else {
|
| - window_->SetBounds(window_bounds);
|
| + window()->SetBounds(window_bounds);
|
| }
|
| +
|
| #if defined(OS_WIN) && !defined(USE_AURA)
|
| std::string app_name = web_app::GenerateApplicationNameFromExtensionId(
|
| extension()->id());
|
| ui::win::SetAppIdForWindow(
|
| ShellIntegration::GetAppModelIdForProfile(
|
| - UTF8ToWide(app_name), shell_window_->profile()->GetPath()),
|
| + UTF8ToWide(app_name), profile()->GetPath()),
|
| GetWidget()->GetTopLevelWidget()->GetNativeWindow());
|
| #endif
|
| -
|
| - extension_keybinding_registry_.reset(
|
| - new ExtensionKeybindingRegistryViews(shell_window_->profile(),
|
| - window_->GetFocusManager(),
|
| - extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY,
|
| - shell_window_));
|
| -
|
| - OnViewWasResized();
|
| -}
|
| -
|
| -views::View* ShellWindowViews::GetInitiallyFocusedView() {
|
| - return web_view_;
|
| -}
|
| -
|
| -bool ShellWindowViews::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
|
| -}
|
| -
|
| -void ShellWindowViews::OnFocus() {
|
| - web_view_->RequestFocus();
|
| -}
|
| -
|
| -void ShellWindowViews::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 ShellWindowViews::GetMinimumSize() {
|
| - return minimum_size_;
|
| -}
|
| -
|
| -gfx::Size ShellWindowViews::GetMaximumSize() {
|
| - return maximum_size_;
|
| -}
|
| -
|
| -void ShellWindowViews::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 ShellWindowViews::IsFullscreenOrPending() const {
|
| - return is_fullscreen_;
|
| -}
|
| -
|
| -ShellWindowViews::~ShellWindowViews() {
|
| - web_view_->SetWebContents(NULL);
|
| -}
|
| -
|
| -bool ShellWindowViews::IsActive() const {
|
| - return window_->IsActive();
|
| -}
|
| -
|
| -bool ShellWindowViews::IsMaximized() const {
|
| - return window_->IsMaximized();
|
| -}
|
| -
|
| -bool ShellWindowViews::IsMinimized() const {
|
| - return window_->IsMinimized();
|
| -}
|
| -
|
| -bool ShellWindowViews::IsFullscreen() const {
|
| - return window_->IsFullscreen();
|
| -}
|
| -
|
| -gfx::NativeWindow ShellWindowViews::GetNativeWindow() {
|
| - return window_->GetNativeWindow();
|
| -}
|
| -
|
| -gfx::Rect ShellWindowViews::GetRestoredBounds() const {
|
| - return window_->GetRestoredBounds();
|
| -}
|
| -
|
| -gfx::Rect ShellWindowViews::GetBounds() const {
|
| - return window_->GetWindowBoundsInScreen();
|
| -}
|
| -
|
| -void ShellWindowViews::Show() {
|
| - if (window_->IsVisible()) {
|
| - window_->Activate();
|
| - return;
|
| - }
|
| -
|
| - window_->Show();
|
| -}
|
| -
|
| -void ShellWindowViews::ShowInactive() {
|
| - if (window_->IsVisible())
|
| - return;
|
| - window_->ShowInactive();
|
| }
|
|
|
| -void ShellWindowViews::Hide() {
|
| - window_->Hide();
|
| -}
|
| -
|
| -void ShellWindowViews::Close() {
|
| - window_->Close();
|
| -}
|
| -
|
| -void ShellWindowViews::Activate() {
|
| - window_->Activate();
|
| -}
|
| -
|
| -void ShellWindowViews::Deactivate() {
|
| - window_->Deactivate();
|
| -}
|
| -
|
| -void ShellWindowViews::Maximize() {
|
| - window_->Maximize();
|
| -}
|
| -
|
| -void ShellWindowViews::Minimize() {
|
| - window_->Minimize();
|
| -}
|
| -
|
| -void ShellWindowViews::Restore() {
|
| - window_->Restore();
|
| -}
|
| -
|
| -void ShellWindowViews::SetBounds(const gfx::Rect& bounds) {
|
| - GetWidget()->SetBounds(bounds);
|
| -}
|
| -
|
| -void ShellWindowViews::FlashFrame(bool flash) {
|
| - window_->FlashFrame(flash);
|
| -}
|
| -
|
| -bool ShellWindowViews::IsAlwaysOnTop() const {
|
| - return false;
|
| -}
|
| -
|
| -void ShellWindowViews::DeleteDelegate() {
|
| - shell_window_->OnNativeClose();
|
| -}
|
| -
|
| -bool ShellWindowViews::CanResize() const {
|
| - return maximum_size_.IsEmpty() || minimum_size_ != maximum_size_;
|
| -}
|
| -
|
| -bool ShellWindowViews::CanMaximize() const {
|
| - return maximum_size_.IsEmpty();
|
| -}
|
| -
|
| -views::View* ShellWindowViews::GetContentsView() {
|
| - return this;
|
| -}
|
| -
|
| -views::NonClientFrameView* ShellWindowViews::CreateNonClientFrameView(
|
| +views::NonClientFrameView* AppWindowViews::CreateNonClientFrameView(
|
| views::Widget* widget) {
|
| #if defined(USE_ASH)
|
| - if (chrome::IsNativeViewInAsh(widget->GetNativeView()) && !frameless_) {
|
| + if (chrome::IsNativeViewInAsh(widget->GetNativeView()) && !frameless()) {
|
| ash::CustomFrameViewAsh* frame = new ash::CustomFrameViewAsh();
|
| frame->Init(widget);
|
| return frame;
|
| }
|
| #endif
|
| ShellWindowFrameView* frame_view = new ShellWindowFrameView(this);
|
| - frame_view->Init(window_);
|
| + frame_view->Init(window());
|
| return frame_view;
|
| }
|
|
|
| -string16 ShellWindowViews::GetWindowTitle() const {
|
| - return shell_window_->GetTitle();
|
| -}
|
| -
|
| -views::Widget* ShellWindowViews::GetWidget() {
|
| - return window_;
|
| -}
|
| -
|
| -const views::Widget* ShellWindowViews::GetWidget() const {
|
| - return window_;
|
| -}
|
| -
|
| -void ShellWindowViews::OnViewWasResized() {
|
| +void AppWindowViews::OnViewWasResized() {
|
| // TODO(jeremya): this doesn't seem like a terribly elegant way to keep the
|
| // window shape in sync.
|
| #if defined(OS_WIN) && !defined(USE_AURA)
|
| // Set the window shape of the RWHV.
|
| - DCHECK(window_);
|
| - DCHECK(web_view_);
|
| - gfx::Size sz = web_view_->size();
|
| + DCHECK(window());
|
| + DCHECK(web_view());
|
| + gfx::Size sz = web_view()->size();
|
| int height = sz.height(), width = sz.width();
|
| int radius = 1;
|
| gfx::Path path;
|
| - if (window_->IsMaximized() || window_->IsFullscreen()) {
|
| + if (window()->IsMaximized() || window()->IsFullscreen()) {
|
| // Don't round the corners when the window is maximized or fullscreen.
|
| path.addRect(0, 0, width, height);
|
| } else {
|
| - if (frameless_) {
|
| + if (frameless()) {
|
| path.moveTo(0, radius);
|
| path.lineTo(radius, 0);
|
| path.lineTo(width - radius, 0);
|
| @@ -650,11 +472,11 @@ void ShellWindowViews::OnViewWasResized() {
|
| SetWindowRgn(web_contents()->GetNativeView(), path.CreateNativeRegion(), 1);
|
|
|
| SkRegion* rgn = new SkRegion;
|
| - if (!window_->IsFullscreen()) {
|
| + if (!window()->IsFullscreen()) {
|
| if (draggable_region())
|
| rgn->op(*draggable_region(), SkRegion::kUnion_Op);
|
| - if (!window_->IsMaximized()) {
|
| - if (frameless_)
|
| + if (!window()->IsMaximized()) {
|
| + if (frameless())
|
| rgn->op(0, 0, width, kResizeInsideBoundsSize, SkRegion::kUnion_Op);
|
| rgn->op(0, 0, kResizeInsideBoundsSize, height, SkRegion::kUnion_Op);
|
| rgn->op(width - kResizeInsideBoundsSize, 0, width, height,
|
| @@ -667,77 +489,3 @@ void ShellWindowViews::OnViewWasResized() {
|
| web_contents()->GetRenderViewHost()->GetView()->SetClickthroughRegion(rgn);
|
| #endif
|
| }
|
| -
|
| -gfx::ImageSkia ShellWindowViews::GetWindowAppIcon() {
|
| - gfx::Image app_icon = shell_window_->app_icon();
|
| - if (app_icon.IsEmpty())
|
| - return GetWindowIcon();
|
| - else
|
| - return *app_icon.ToImageSkia();
|
| -}
|
| -
|
| -gfx::ImageSkia ShellWindowViews::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 ShellWindowViews::ShouldShowWindowTitle() const {
|
| - return false;
|
| -}
|
| -
|
| -void ShellWindowViews::OnWidgetMove() {
|
| - shell_window_->SaveWindowPosition();
|
| -}
|
| -
|
| -void ShellWindowViews::Layout() {
|
| - DCHECK(web_view_);
|
| - web_view_->SetBounds(0, 0, width(), height());
|
| - OnViewWasResized();
|
| -}
|
| -
|
| -void ShellWindowViews::UpdateWindowIcon() {
|
| - window_->UpdateWindowIcon();
|
| -}
|
| -
|
| -void ShellWindowViews::UpdateWindowTitle() {
|
| - window_->UpdateWindowTitle();
|
| -}
|
| -
|
| -void ShellWindowViews::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 ShellWindowViews::HandleKeyboardEvent(
|
| - const content::NativeWebKeyboardEvent& event) {
|
| - unhandled_keyboard_event_handler_.HandleKeyboardEvent(event,
|
| - GetFocusManager());
|
| -}
|
| -
|
| -void ShellWindowViews::RenderViewHostChanged() {
|
| - OnViewWasResized();
|
| -}
|
| -
|
| -void ShellWindowViews::SaveWindowPlacement(const gfx::Rect& bounds,
|
| - ui::WindowShowState show_state) {
|
| - views::WidgetDelegate::SaveWindowPlacement(bounds, show_state);
|
| - shell_window_->SaveWindowPosition();
|
| -}
|
| -
|
| -// static
|
| -NativeShellWindow* NativeShellWindow::Create(
|
| - ShellWindow* shell_window, const ShellWindow::CreateParams& params) {
|
| - return new ShellWindowViews(shell_window, params);
|
| -}
|
|
|