summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-26 22:55:28 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-26 22:55:28 +0000
commit4d34e2ef8022e6a7771c6f4cd171547fc4b60518 (patch)
treeb90d1071552813de90df3bbcd9cc82bd1202ac9a /chrome
parent122262403bda963a3bfd93aab68a3c2861de584f (diff)
downloadchromium_src-4d34e2ef8022e6a7771c6f4cd171547fc4b60518.zip
chromium_src-4d34e2ef8022e6a7771c6f4cd171547fc4b60518.tar.gz
chromium_src-4d34e2ef8022e6a7771c6f4cd171547fc4b60518.tar.bz2
Add a single monitor implementation of WindowSizer for Linux. (try 2)
BUG=10005 Review URL: http://codereview.chromium.org/115723 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16940 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/browser.cc15
-rw-r--r--chrome/browser/extensions/extension_tabs_module.cc7
-rw-r--r--chrome/browser/gtk/browser_window_gtk.cc13
-rw-r--r--chrome/browser/window_sizer_linux.cc86
-rw-r--r--chrome/chrome.gyp4
-rw-r--r--chrome/common/temp_scaffolding_stubs.cc27
-rw-r--r--chrome/common/temp_scaffolding_stubs.h16
7 files changed, 118 insertions, 50 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index 7c0f84d..9050f19 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -36,6 +36,7 @@
#include "chrome/browser/tab_contents/site_instance.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/tab_contents_view.h"
+#include "chrome/browser/window_sizer.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension.h"
@@ -77,10 +78,6 @@
#include "chrome/common/child_process_host.h"
#endif // OS_WIN
-#if defined(OS_WIN) || defined(OS_MACOSX)
-#include "chrome/browser/window_sizer.h"
-#endif
-
#if defined(TOOLKIT_VIEWS)
#include "chrome/browser/dock_info.h"
#endif
@@ -1802,7 +1799,8 @@ void Browser::AddNewContents(TabContents* source,
// AddTabContents method does.
if (type_ & TYPE_APP)
transition = PageTransition::START_PAGE;
- b->tabstrip_model()->AddTabContents(new_contents, -1, false, transition, true);
+ b->tabstrip_model()->AddTabContents(new_contents, -1, false, transition,
+ true);
b->window()->Show();
return;
}
@@ -1815,7 +1813,8 @@ void Browser::AddNewContents(TabContents* source,
initial_pos, user_gesture);
browser->window()->Show();
} else if (disposition != SUPPRESS_OPEN) {
- tabstrip_model_.AddTabContents(new_contents, -1, false, PageTransition::LINK,
+ tabstrip_model_.AddTabContents(new_contents, -1, false,
+ PageTransition::LINK,
disposition == NEW_FOREGROUND_TAB);
}
}
@@ -2364,8 +2363,10 @@ void Browser::ProcessPendingUIUpdates() {
// Updating the URL happens synchronously in ScheduleUIUpdate.
TabContents* selected_tab = GetSelectedTabContents();
- if (selected_tab && flags & TabContents::INVALIDATE_LOAD && GetStatusBubble())
+ if (selected_tab &&
+ flags & TabContents::INVALIDATE_LOAD && GetStatusBubble()) {
GetStatusBubble()->SetStatus(selected_tab->GetStatusText());
+ }
if (flags & TabContents::INVALIDATE_TAB) {
tabstrip_model_.UpdateTabContentsStateAt(
diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc
index 5533ff5..6bd2244 100644
--- a/chrome/browser/extensions/extension_tabs_module.cc
+++ b/chrome/browser/extensions/extension_tabs_module.cc
@@ -12,15 +12,10 @@
#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/renderer_host/render_view_host_delegate.h"
#include "chrome/browser/tab_contents/navigation_entry.h"
+#include "chrome/browser/window_sizer.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_error_utils.h"
-// TODO(port): Port these files.
-#if defined(OS_WIN) || defined(OS_MACOSX)
-#include "chrome/browser/window_sizer.h"
-#else
-#include "chrome/common/temp_scaffolding_stubs.h"
-#endif
namespace keys = extension_tabs_module_constants;
diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc
index 24d4509..dac71c3 100644
--- a/chrome/browser/gtk/browser_window_gtk.cc
+++ b/chrome/browser/gtk/browser_window_gtk.cc
@@ -740,13 +740,21 @@ void BrowserWindowGtk::AddFindBar(FindBarGtk* findbar) {
}
void BrowserWindowGtk::SetGeometryHints() {
- gtk_window_set_default_size(window_, 640, 480);
-
// Allow the user to resize us arbitrarily small.
GdkGeometry geometry;
geometry.min_width = 1;
geometry.min_height = 1;
gtk_window_set_geometry_hints(window_, NULL, &geometry, GDK_HINT_MIN_SIZE);
+
+ if (browser_->GetSavedMaximizedState())
+ gtk_window_maximize(window_);
+ else
+ gtk_window_unmaximize(window_);
+
+ gfx::Rect rect = browser_->GetSavedWindowBounds();
+ gtk_window_set_default_size(window_,
+ static_cast<gint>(rect.width()),
+ static_cast<gint>(rect.height()));
}
void BrowserWindowGtk::SetWindowIcon() {
@@ -826,4 +834,3 @@ bool BrowserWindowGtk::IsToolbarSupported() {
return browser_->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) ||
browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR);
}
-
diff --git a/chrome/browser/window_sizer_linux.cc b/chrome/browser/window_sizer_linux.cc
new file mode 100644
index 0000000..cd44490
--- /dev/null
+++ b/chrome/browser/window_sizer_linux.cc
@@ -0,0 +1,86 @@
+// Copyright (c) 2009 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/window_sizer.h"
+
+#include <gtk/gtk.h>
+
+#include "base/logging.h"
+#include "chrome/browser/browser.h"
+
+// How much horizontal and vertical offset there is between newly
+// opened windows. We don't care on Linux since the window manager generally
+// does a good job of window placement.
+const int WindowSizer::kWindowTilePixels = 0;
+
+// An implementation of WindowSizer::MonitorInfoProvider that gets the actual
+// monitor information from X via GDK.
+class DefaultMonitorInfoProvider : public WindowSizer::MonitorInfoProvider {
+ public:
+ DefaultMonitorInfoProvider() { }
+
+ virtual gfx::Rect GetPrimaryMonitorWorkArea() const {
+ gfx::Rect rect = GetScreenWorkArea();
+ return rect.Intersect(GetPrimaryMonitorBounds());
+ }
+
+ virtual gfx::Rect GetPrimaryMonitorBounds() const {
+ GdkScreen* screen = gdk_screen_get_default();
+ GdkRectangle rect;
+ gdk_screen_get_monitor_geometry(screen, 0, &rect);
+ return gfx::Rect(rect);
+ }
+
+ virtual gfx::Rect GetMonitorWorkAreaMatching(
+ const gfx::Rect& match_rect) const {
+ // TODO(thestig) Implement multi-monitor support.
+ return GetPrimaryMonitorWorkArea();
+ }
+
+ virtual gfx::Point GetBoundsOffsetMatching(
+ const gfx::Rect& match_rect) const {
+ // TODO(thestig) Implement multi-monitor support.
+ return GetPrimaryMonitorWorkArea().origin();
+ }
+
+ void UpdateWorkAreas() {
+ // TODO(thestig) Implement multi-monitor support.
+ work_areas_.clear();
+ work_areas_.push_back(GetPrimaryMonitorBounds());
+ }
+
+ private:
+ gfx::Rect GetScreenWorkArea() const {
+ gboolean r;
+ guchar* raw_data;
+ gint data_len;
+ r = gdk_property_get(gdk_get_default_root_window(), // a gdk window
+ gdk_atom_intern("_NET_WORKAREA", FALSE), // property
+ gdk_atom_intern("CARDINAL", FALSE), // property type
+ 0, // byte offset into property
+ 0xff, // property length to retrieve
+ false, // delete property after retrieval?
+ NULL, // returned property type
+ NULL, // returned data format
+ &data_len, // returned data len
+ &raw_data); // returned data
+ CHECK(r);
+ CHECK(data_len >= 16);
+ glong* data = reinterpret_cast<glong*>(raw_data);
+ gint x = data[0];
+ gint y = data[1];
+ gint width = data[0] + data[2];
+ gint height = data[1] + data[3];
+ g_free(data);
+ return gfx::Rect(x, y, width, height);
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(DefaultMonitorInfoProvider);
+};
+
+// static
+WindowSizer::MonitorInfoProvider*
+WindowSizer::CreateDefaultMonitorInfoProvider() {
+ return new DefaultMonitorInfoProvider();
+}
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 0a01353..262fe2d 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -1530,6 +1530,7 @@
'browser/window_sizer.cc',
'browser/window_sizer.h',
'browser/window_sizer_mac.mm',
+ 'browser/window_sizer_linux.cc',
'browser/window_sizer_win.cc',
'browser/worker_host/worker_process_host.cc',
'browser/worker_host/worker_process_host.h',
@@ -1552,9 +1553,6 @@
'../build/linux/system.gyp:gtk',
],
'sources!': [
- # TODO(port): add this to the Linux build once a
- # window_sizer_linux.cc is written
- 'browser/window_sizer.cc',
'browser/debugger/debugger_shell_stubs.cc',
# Windows-specific files.
'browser/download/download_exe.cc',
diff --git a/chrome/common/temp_scaffolding_stubs.cc b/chrome/common/temp_scaffolding_stubs.cc
index 50aa826..f54b27f 100644
--- a/chrome/common/temp_scaffolding_stubs.cc
+++ b/chrome/common/temp_scaffolding_stubs.cc
@@ -8,6 +8,7 @@
#include <vector>
+#include "base/gfx/rect.h"
#include "base/logging.h"
#include "chrome/browser/automation/automation_provider.h"
#include "chrome/browser/download/download_request_dialog_delegate.h"
@@ -281,22 +282,6 @@ void DragDownload(const DownloadItem* download, SkBitmap* icon) {
} // namespace download_util
-#if defined(OS_LINUX)
-void WindowSizer::GetBrowserWindowBounds(const std::wstring& app_name,
- const gfx::Rect& specified_bounds,
- Browser* browser,
- gfx::Rect* window_bounds,
- bool* maximized) {
- // If we're given a bounds, use it (for things like tearing off tabs during
- // drags). If not, make up something reasonable until the rest of the
- // WindowSizer infrastructure is in place.
- *window_bounds = specified_bounds;
- if (specified_bounds.IsEmpty()) {
- *window_bounds = gfx::Rect(0, 0, 1024, 768);
- }
-}
-#endif
-
#if defined(OS_MACOSX)
void HungRendererDialog::HideForTabContents(TabContents*) {
NOTIMPLEMENTED();
@@ -321,3 +306,13 @@ void ShowOptionsWindow(OptionsPage page,
NOTIMPLEMENTED();
}
#endif
+
+#if !defined(TOOLKIT_VIEWS)
+bool DockInfo::GetNewWindowBounds(gfx::Rect* new_window_bounds,
+ bool* maximize_new_window) const {
+ NOTIMPLEMENTED();
+ // Return a reasonable default
+ *new_window_bounds = gfx::Rect(640, 480);
+ return true;
+}
+#endif
diff --git a/chrome/common/temp_scaffolding_stubs.h b/chrome/common/temp_scaffolding_stubs.h
index 630d8dd..300c240 100644
--- a/chrome/common/temp_scaffolding_stubs.h
+++ b/chrome/common/temp_scaffolding_stubs.h
@@ -339,25 +339,11 @@ class FaviconStatus {
#if !defined(TOOLKIT_VIEWS)
class DockInfo {
public:
- bool GetNewWindowBounds(gfx::Rect*, bool*) const {
- NOTIMPLEMENTED();
- return false;
- }
+ bool GetNewWindowBounds(gfx::Rect*, bool*) const;
void AdjustOtherWindowBounds() const { NOTIMPLEMENTED(); }
};
#endif
-#if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
-class WindowSizer {
- public:
- static void GetBrowserWindowBounds(const std::wstring& app_name,
- const gfx::Rect& specified_bounds,
- Browser* browser,
- gfx::Rect* window_bounds,
- bool* maximized);
-};
-#endif
-
//---------------------------------------------------------------------------
// These stubs are for Profile