Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1406)

Unified Diff: chrome/browser/ui/views/extensions/shell_window_frame_view.cc

Issue 11363250: Allow Chrome apps to create Ash Panels (apps v2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix mac and win builds Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/views/extensions/shell_window_frame_view.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/extensions/shell_window_frame_view.cc
diff --git a/chrome/browser/ui/views/extensions/native_app_window_views.cc b/chrome/browser/ui/views/extensions/shell_window_frame_view.cc
similarity index 50%
copy from chrome/browser/ui/views/extensions/native_app_window_views.cc
copy to chrome/browser/ui/views/extensions/shell_window_frame_view.cc
index df16fd4fcd9a13b85cfbe1126addd378dc9f4a84..3d8b761bcf68bedc5b56651435260cd2d8988033 100644
--- a/chrome/browser/ui/views/extensions/native_app_window_views.cc
+++ b/chrome/browser/ui/views/extensions/shell_window_frame_view.cc
@@ -2,18 +2,11 @@
// 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/native_app_window_views.h"
+#include "chrome/browser/ui/views/extensions/shell_window_frame_view.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/browser/ui/views/extensions/native_app_window_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"
@@ -23,13 +16,10 @@
#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 "chrome/browser/shell_integration.h"
@@ -39,7 +29,6 @@
#if defined(USE_ASH)
#include "ash/ash_constants.h"
-#include "ash/wm/custom_frame_view_ash.h"
#include "chrome/browser/ui/ash/ash_util.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
@@ -53,49 +42,6 @@ const int kResizeAreaCornerSize = 16;
const int kCaptionHeight = 25;
} // namespace
-class ShellWindowFrameView : public views::NonClientFrameView,
- public views::ButtonListener {
- public:
- static const char kViewClassName[];
-
- explicit ShellWindowFrameView(NativeAppWindowViews* window);
- virtual ~ShellWindowFrameView();
-
- void Init(views::Widget* frame);
-
- // views::NonClientFrameView implementation.
- virtual gfx::Rect GetBoundsForClientView() const OVERRIDE;
- virtual gfx::Rect GetWindowBoundsForClientBounds(
- const gfx::Rect& client_bounds) const OVERRIDE;
- virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE;
- virtual void GetWindowMask(const gfx::Size& size,
- gfx::Path* window_mask) OVERRIDE;
- virtual void ResetWindowControls() OVERRIDE {}
- virtual void UpdateWindowIcon() OVERRIDE {}
- virtual void UpdateWindowTitle() OVERRIDE {}
-
- // views::View implementation.
- virtual gfx::Size GetPreferredSize() OVERRIDE;
- virtual void Layout() OVERRIDE;
- virtual std::string GetClassName() const OVERRIDE;
- virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
- virtual gfx::Size GetMinimumSize() OVERRIDE;
- virtual gfx::Size GetMaximumSize() OVERRIDE;
-
- private:
- // views::ButtonListener implementation.
- virtual void ButtonPressed(views::Button* sender, const ui::Event& event)
- OVERRIDE;
-
- NativeAppWindowViews* window_;
- views::Widget* frame_;
- views::ImageButton* close_button_;
- views::ImageButton* maximize_button_;
- views::ImageButton* restore_button_;
- views::ImageButton* minimize_button_;
-
- DISALLOW_COPY_AND_ASSIGN(ShellWindowFrameView);
-};
const char ShellWindowFrameView::kViewClassName[] =
"browser/ui/views/extensions/ShellWindowFrameView";
@@ -178,6 +124,8 @@ void ShellWindowFrameView::Init(views::Widget* frame) {
#endif
}
+// views::NonClientFrameView implementation.
+
gfx::Rect ShellWindowFrameView::GetBoundsForClientView() const {
if (window_->frameless() || frame_->IsFullscreen())
return bounds();
@@ -274,6 +222,8 @@ void ShellWindowFrameView::GetWindowMask(const gfx::Size& size,
// We got nothing to say about no window mask.
}
+// views::View implementation.
+
gfx::Size ShellWindowFrameView::GetPreferredSize() {
gfx::Size pref = frame_->client_view()->GetPreferredSize();
gfx::Rect bounds(0, 0, pref.width(), pref.height());
@@ -382,6 +332,8 @@ gfx::Size ShellWindowFrameView::GetMaximumSize() {
return max_size;
}
+// views::ButtonListener implementation.
+
void ShellWindowFrameView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
DCHECK(!window_->frameless());
@@ -394,363 +346,3 @@ void ShellWindowFrameView::ButtonPressed(views::Button* sender,
else if (sender == minimize_button_)
frame_->Minimize();
}
-
-NativeAppWindowViews::NativeAppWindowViews(
- 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;
- 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);
- gfx::Rect window_bounds =
- window_->non_client_view()->GetWindowBoundsForClientBounds(
- win_params.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());
- } else {
- 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()),
- GetWidget()->GetTopLevelWidget()->GetNativeWindow());
-#endif
-
- extension_keybinding_registry_.reset(
- new ExtensionKeybindingRegistryViews(shell_window_->profile(),
- window_->GetFocusManager(),
- extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY,
- shell_window_));
-
- OnViewWasResized();
- window_->AddObserver(this);
-}
-
-views::View* NativeAppWindowViews::GetInitiallyFocusedView() {
- return web_view_;
-}
-
-bool NativeAppWindowViews::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 NativeAppWindowViews::OnFocus() {
- web_view_->RequestFocus();
-}
-
-void NativeAppWindowViews::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 NativeAppWindowViews::GetMinimumSize() {
- return minimum_size_;
-}
-
-gfx::Size NativeAppWindowViews::GetMaximumSize() {
- return maximum_size_;
-}
-
-void NativeAppWindowViews::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 NativeAppWindowViews::IsFullscreenOrPending() const {
- return is_fullscreen_;
-}
-
-NativeAppWindowViews::~NativeAppWindowViews() {
- web_view_->SetWebContents(NULL);
-}
-
-bool NativeAppWindowViews::IsActive() const {
- return window_->IsActive();
-}
-
-bool NativeAppWindowViews::IsMaximized() const {
- return window_->IsMaximized();
-}
-
-bool NativeAppWindowViews::IsMinimized() const {
- return window_->IsMinimized();
-}
-
-bool NativeAppWindowViews::IsFullscreen() const {
- return window_->IsFullscreen();
-}
-
-gfx::NativeWindow NativeAppWindowViews::GetNativeWindow() {
- return window_->GetNativeWindow();
-}
-
-gfx::Rect NativeAppWindowViews::GetRestoredBounds() const {
- return window_->GetRestoredBounds();
-}
-
-gfx::Rect NativeAppWindowViews::GetBounds() const {
- return window_->GetWindowBoundsInScreen();
-}
-
-void NativeAppWindowViews::Show() {
- if (window_->IsVisible()) {
- window_->Activate();
- return;
- }
-
- window_->Show();
-}
-
-void NativeAppWindowViews::ShowInactive() {
- if (window_->IsVisible())
- return;
- window_->ShowInactive();
-}
-
-void NativeAppWindowViews::Hide() {
- window_->Hide();
-}
-
-void NativeAppWindowViews::Close() {
- window_->Close();
-}
-
-void NativeAppWindowViews::Activate() {
- window_->Activate();
-}
-
-void NativeAppWindowViews::Deactivate() {
- window_->Deactivate();
-}
-
-void NativeAppWindowViews::Maximize() {
- window_->Maximize();
-}
-
-void NativeAppWindowViews::Minimize() {
- window_->Minimize();
-}
-
-void NativeAppWindowViews::Restore() {
- window_->Restore();
-}
-
-void NativeAppWindowViews::SetBounds(const gfx::Rect& bounds) {
- GetWidget()->SetBounds(bounds);
-}
-
-void NativeAppWindowViews::FlashFrame(bool flash) {
- window_->FlashFrame(flash);
-}
-
-bool NativeAppWindowViews::IsAlwaysOnTop() const {
- return false;
-}
-
-void NativeAppWindowViews::DeleteDelegate() {
- window_->RemoveObserver(this);
- shell_window_->OnNativeClose();
-}
-
-bool NativeAppWindowViews::CanResize() const {
- return maximum_size_.IsEmpty() || minimum_size_ != maximum_size_;
-}
-
-bool NativeAppWindowViews::CanMaximize() const {
- return maximum_size_.IsEmpty();
-}
-
-views::View* NativeAppWindowViews::GetContentsView() {
- return this;
-}
-
-views::NonClientFrameView* NativeAppWindowViews::CreateNonClientFrameView(
- views::Widget* widget) {
-#if defined(USE_ASH)
- 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_);
- return frame_view;
-}
-
-string16 NativeAppWindowViews::GetWindowTitle() const {
- return shell_window_->GetTitle();
-}
-
-views::Widget* NativeAppWindowViews::GetWidget() {
- return window_;
-}
-
-const views::Widget* NativeAppWindowViews::GetWidget() const {
- return window_;
-}
-
-void NativeAppWindowViews::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();
- int height = sz.height(), width = sz.width();
- int radius = 1;
- gfx::Path path;
- 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_) {
- path.moveTo(0, radius);
- path.lineTo(radius, 0);
- path.lineTo(width - radius, 0);
- path.lineTo(width, radius);
- } else {
- // Don't round the top corners in chrome-style frame mode.
- path.moveTo(0, 0);
- path.lineTo(width, 0);
- }
- path.lineTo(width, height - radius - 1);
- path.lineTo(width - radius - 1, height);
- path.lineTo(radius + 1, height);
- path.lineTo(0, height - radius - 1);
- path.close();
- }
- SetWindowRgn(web_contents()->GetNativeView(), path.CreateNativeRegion(), 1);
-
- SkRegion* rgn = new SkRegion;
- if (!window_->IsFullscreen()) {
- if (draggable_region())
- rgn->op(*draggable_region(), SkRegion::kUnion_Op);
- 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,
- SkRegion::kUnion_Op);
- rgn->op(0, height - kResizeInsideBoundsSize, width, height,
- SkRegion::kUnion_Op);
- }
- }
- if (web_contents()->GetRenderViewHost()->GetView())
- web_contents()->GetRenderViewHost()->GetView()->SetClickthroughRegion(rgn);
-#endif
-}
-
-gfx::ImageSkia NativeAppWindowViews::GetWindowAppIcon() {
- gfx::Image app_icon = shell_window_->app_icon();
- if (app_icon.IsEmpty())
- return GetWindowIcon();
- else
- return *app_icon.ToImageSkia();
-}
-
-gfx::ImageSkia NativeAppWindowViews::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 NativeAppWindowViews::ShouldShowWindowTitle() const {
- return false;
-}
-
-void NativeAppWindowViews::OnWidgetMove() {
- shell_window_->OnNativeWindowChanged();
-}
-
-void NativeAppWindowViews::OnWidgetVisibilityChanged(views::Widget* widget,
- bool visible) {
- shell_window_->OnNativeWindowChanged();
-}
-
-void NativeAppWindowViews::OnWidgetActivationChanged(views::Widget* widget,
- bool active) {
- shell_window_->OnNativeWindowChanged();
-}
-
-void NativeAppWindowViews::Layout() {
- DCHECK(web_view_);
- web_view_->SetBounds(0, 0, width(), height());
- OnViewWasResized();
-}
-
-void NativeAppWindowViews::UpdateWindowIcon() {
- window_->UpdateWindowIcon();
-}
-
-void NativeAppWindowViews::UpdateWindowTitle() {
- window_->UpdateWindowTitle();
-}
-
-void NativeAppWindowViews::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 NativeAppWindowViews::HandleKeyboardEvent(
- const content::NativeWebKeyboardEvent& event) {
- unhandled_keyboard_event_handler_.HandleKeyboardEvent(event,
- GetFocusManager());
-}
-
-void NativeAppWindowViews::RenderViewHostChanged() {
- OnViewWasResized();
-}
-
-void NativeAppWindowViews::SaveWindowPlacement(const gfx::Rect& bounds,
- ui::WindowShowState show_state) {
- views::WidgetDelegate::SaveWindowPlacement(bounds, show_state);
- shell_window_->OnNativeWindowChanged();
-}
-
-// static
-NativeAppWindow* NativeAppWindow::Create(
- ShellWindow* shell_window, const ShellWindow::CreateParams& params) {
- return new NativeAppWindowViews(shell_window, params);
-}
« no previous file with comments | « chrome/browser/ui/views/extensions/shell_window_frame_view.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698