Commit 1b1989f5 authored by jeremya@chromium.org's avatar jeremya@chromium.org

Add a way to fetch window frame metrics from NativeShellWindow

This adds default implementations to the Cocoa and Gtk shell windows. The views shell window is currently the only class that implements these in a non-default way; the Cocoa and Gtk will get their own implementations in a follow-up patch.

This is needed to have the app window setBounds() and getBounds() APIs operate
on content bounds rather than window frame bounds.

R=ben@chromium.org,rsesek@chromium.org,estade@chromium.org

Review URL: https://chromiumcodereview.appspot.com/11369237

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170713 0039d316-1c4b-4281-b951-d872f2087c98
parent 4530fdf4
......@@ -5,6 +5,7 @@
#include "chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.h"
#include "chrome/browser/extensions/shell_window_registry.h"
#include "chrome/browser/ui/extensions/native_app_window.h"
#include "chrome/browser/ui/extensions/shell_window.h"
#include "chrome/common/extensions/api/app_current_window_internal.h"
......
......@@ -10,6 +10,7 @@
#include "chrome/browser/debugger/devtools_window.h"
#include "chrome/browser/extensions/shell_window_registry.h"
#include "chrome/browser/extensions/window_controller.h"
#include "chrome/browser/ui/extensions/native_app_window.h"
#include "chrome/browser/ui/extensions/shell_window.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "chrome/common/chrome_switches.h"
......
......@@ -5,7 +5,7 @@
#include "base/string_number_conversions.h"
#include "chrome/browser/extensions/extension_test_message_listener.h"
#include "chrome/browser/extensions/platform_app_browsertest_util.h"
#include "chrome/browser/ui/base_window.h"
#include "chrome/browser/ui/extensions/native_app_window.h"
#include "chrome/browser/ui/extensions/shell_window.h"
#include "ui/gfx/rect.h"
......
......@@ -28,6 +28,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/extensions/native_app_window.h"
#include "chrome/browser/ui/extensions/shell_window.h"
#include "chrome/browser/ui/omnibox/location_bar.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
......
......@@ -28,6 +28,7 @@
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/constrained_window_tab_helper.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/browser/ui/extensions/native_app_window.h"
#include "chrome/browser/ui/extensions/shell_window.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "chrome/common/chrome_notification_types.h"
......
......@@ -12,6 +12,7 @@
#include "chrome/browser/extensions/shell_window_registry.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/browser/ui/extensions/native_app_window.h"
#include "chrome/browser/ui/extensions/shell_window.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
......
......@@ -4,6 +4,7 @@
#include "chrome/browser/extensions/shell_window_registry.h"
#include "chrome/browser/profiles/profile_dependency_manager.h"
#include "chrome/browser/ui/extensions/native_app_window.h"
#include "chrome/browser/ui/extensions/shell_window.h"
#include "chrome/common/extensions/extension.h"
#include "content/public/browser/notification_types.h"
......
......@@ -15,6 +15,7 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
#include "chrome/browser/ui/extensions/native_app_window.h"
#include "chrome/browser/ui/extensions/shell_window.h"
#include "chrome/common/extensions/extension.h"
#include "ui/aura/client/activation_client.h"
......
......@@ -110,6 +110,7 @@ class NativeAppWindowCocoa : public NativeAppWindow {
virtual void HandleKeyboardEvent(
const content::NativeWebKeyboardEvent& event) OVERRIDE;
virtual void RenderViewHostChanged() OVERRIDE {}
virtual gfx::Insets GetFrameInsets() const OVERRIDE;
private:
virtual ~NativeAppWindowCocoa();
......
......@@ -655,6 +655,10 @@ bool NativeAppWindowCocoa::IsAlwaysOnTop() const {
return false;
}
gfx::Insets NativeAppWindowCocoa::GetFrameInsets() const {
return gfx::Insets();
}
void NativeAppWindowCocoa::WindowWillClose() {
[window_controller_ setAppWindow:NULL];
shell_window_->OnNativeWindowChanged();
......
......@@ -7,6 +7,7 @@
#include "chrome/browser/ui/base_window.h"
#include "chrome/browser/ui/extensions/shell_window.h"
#include "ui/gfx/insets.h"
// This is an interface to a native implementation of a shell window, used for
// new-style packaged apps. Shell windows contain a web contents, but no tabs
......@@ -39,6 +40,10 @@ class NativeAppWindow : public BaseWindow {
// this.
virtual void RenderViewHostChanged() = 0;
// Returns the difference between the window bounds (including titlebar and
// borders) and the content bounds, if any.
virtual gfx::Insets GetFrameInsets() const = 0;
virtual ~NativeAppWindow() {}
};
......
......@@ -351,11 +351,14 @@ void ShellWindow::OnNativeWindowChanged() {
false));
}
BaseWindow* ShellWindow::GetBaseWindow() {
NativeAppWindow* ShellWindow::GetBaseWindow() {
return native_app_window_.get();
}
gfx::NativeWindow ShellWindow::GetNativeWindow() {
return GetBaseWindow()->GetNativeWindow();
}
string16 ShellWindow::GetTitle() const {
// WebContents::GetTitle() will return the page's URL if there's no <title>
// specified. However, we'd prefer to show the name of the extension in that
......
......@@ -61,9 +61,9 @@ class ShellWindow : public content::NotificationObserver,
WindowType window_type;
Frame frame;
// Specify the initial bounds of the window. INT_MIN designates
// 'unspecified' for any coordinate, and should be replaced with a default
// value.
// Specify the initial content bounds of the window (excluding any window
// decorations). INT_MIN designates 'unspecified' for any coordinate, and
// should be replaced with a default value.
gfx::Rect bounds;
gfx::Size minimum_size;
......@@ -96,10 +96,8 @@ class ShellWindow : public content::NotificationObserver,
Profile* profile() const { return profile_; }
const gfx::Image& app_icon() const { return app_icon_; }
BaseWindow* GetBaseWindow();
gfx::NativeWindow GetNativeWindow() {
return GetBaseWindow()->GetNativeWindow();
}
NativeAppWindow* GetBaseWindow();
gfx::NativeWindow GetNativeWindow();
// NativeAppWindows should call this to determine what the window's title
// is on startup and from within UpdateWindowTitle().
......
......@@ -227,6 +227,10 @@ bool NativeAppWindowGtk::IsAlwaysOnTop() const {
return false;
}
gfx::Insets NativeAppWindowGtk::GetFrameInsets() const {
return gfx::Insets();
}
void NativeAppWindowGtk::ActiveWindowChanged(GdkWindow* active_window) {
// Do nothing if we're in the process of closing the browser window.
if (!window_)
......
......@@ -65,6 +65,7 @@ class NativeAppWindowGtk : public NativeAppWindow,
virtual void UpdateDraggableRegions(
const std::vector<extensions::DraggableRegion>& regions) OVERRIDE;
virtual void RenderViewHostChanged() OVERRIDE {}
virtual gfx::Insets GetFrameInsets() const OVERRIDE;
content::WebContents* web_contents() const {
return shell_window_->web_contents();
......
......@@ -78,9 +78,8 @@ void NativeAppWindowViews::InitializeDefaultWindow(
init_params.remove_standard_frame = true;
init_params.use_system_default_icon = true;
window_->Init(init_params);
gfx::Rect window_bounds =
window_->non_client_view()->GetWindowBoundsForClientBounds(
create_params.bounds);
gfx::Rect window_bounds = create_params.bounds;
window_bounds.Inset(-GetFrameInsets());
// Center window if no position was specified.
if (create_params.bounds.x() == INT_MIN ||
create_params.bounds.y() == INT_MIN) {
......@@ -210,6 +209,22 @@ bool NativeAppWindowViews::IsAlwaysOnTop() const {
return shell_window_->window_type() == ShellWindow::WINDOW_TYPE_PANEL;
}
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 =
window_->non_client_view()->GetWindowBoundsForClientBounds(
client_bounds);
return window_bounds.InsetsFrom(client_bounds);
}
// Private method. TODO(stevenjb): Move this below InitializePanelWindow()
// to match declaration order.
void NativeAppWindowViews::OnViewWasResized() {
......
......@@ -113,6 +113,7 @@ class NativeAppWindowViews : public NativeAppWindow,
virtual void HandleKeyboardEvent(
const content::NativeWebKeyboardEvent& event) OVERRIDE;
virtual void RenderViewHostChanged() OVERRIDE;
virtual gfx::Insets GetFrameInsets() const OVERRIDE;
Profile* profile() { return shell_window_->profile(); }
content::WebContents* web_contents() {
......
......@@ -27,6 +27,7 @@
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/chrome_select_file_policy.h"
#include "chrome/browser/ui/extensions/native_app_window.h"
#include "chrome/browser/ui/extensions/shell_window.h"
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/browser/ui/views/extensions/extension_dialog.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment