Skip to content

Commit

Permalink
This adds in the ability for Chrome to generate windows with snapshots
Browse files Browse the repository at this point in the history
of all currently open tabs in all browsers.

This is needed for overview mode on ChromeOS.

BUG=http://code.google.com/p/chromium-os/issues/detail?id=1170
TEST=Ran Chrome under ChromeOS with updated window manager.
Review URL: http://codereview.chromium.org/661237

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45824 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
gspencer@chromium.org committed Apr 28, 2010
1 parent 7cea56d commit d65adb1
Show file tree
Hide file tree
Showing 28 changed files with 1,297 additions and 102 deletions.
21 changes: 21 additions & 0 deletions app/surface/transport_dib.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ class TransportDIB {
// Returns a default, invalid handle, that is meant to indicate a missing
// Transport DIB.
static Handle DefaultHandleValue() { return NULL; }

// Returns a value that is ONLY USEFUL FOR TESTS WHERE IT WON'T BE
// ACTUALLY USED AS A REAL HANDLE.
static Handle GetFakeHandleForTest() {
static int fake_handle = 10;
return reinterpret_cast<Handle>(fake_handle++);
}
#elif defined(OS_MACOSX)
typedef base::SharedMemoryHandle Handle;
// On Mac, the inode number of the backing file is used as an id.
Expand All @@ -81,13 +88,27 @@ class TransportDIB {
// Returns a default, invalid handle, that is meant to indicate a missing
// Transport DIB.
static Handle DefaultHandleValue() { return Handle(); }

// Returns a value that is ONLY USEFUL FOR TESTS WHERE IT WON'T BE
// ACTUALLY USED AS A REAL HANDLE.
static Handle GetFakeHandleForTest() {
static int fake_handle = 10;
return Handle(fake_handle++, false);
}
#elif defined(USE_X11)
typedef int Handle; // These two ints are SysV IPC shared memory keys
typedef int Id;

// Returns a default, invalid handle, that is meant to indicate a missing
// Transport DIB.
static Handle DefaultHandleValue() { return -1; }

// Returns a value that is ONLY USEFUL FOR TESTS WHERE IT WON'T BE
// ACTUALLY USED AS A REAL HANDLE.
static Handle GetFakeHandleForTest() {
static int fake_handle = 10;
return fake_handle++;
}
#endif

// Create a new TransportDIB, returning NULL on failure.
Expand Down
38 changes: 38 additions & 0 deletions app/x11_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,44 @@ bool GetIntProperty(XID window, const std::string& property_name, int* value) {
return true;
}

bool GetIntArrayProperty(XID window,
const std::string& property_name,
std::vector<int>* value) {
Atom property_atom = gdk_x11_get_xatom_by_name_for_display(
gdk_display_get_default(), property_name.c_str());

Atom type = None;
int format = 0; // size in bits of each item in 'property'
long unsigned int num_items = 0, remaining_bytes = 0;
unsigned char* properties = NULL;

int result = XGetWindowProperty(GetXDisplay(),
window,
property_atom,
0, // offset into property data to read
(~0L), // max length to get (all of them)
False, // deleted
AnyPropertyType,
&type,
&format,
&num_items,
&remaining_bytes,
&properties);
if (result != Success)
return false;

if (format != 32) {
XFree(properties);
return false;
}

int* int_properties = reinterpret_cast<int*>(properties);
value->clear();
value->insert(value->begin(), int_properties, int_properties + num_items);
XFree(properties);
return true;
}

bool GetStringProperty(
XID window, const std::string& property_name, std::string* value) {
Atom property_atom = gdk_x11_get_xatom_by_name_for_display(
Expand Down
6 changes: 4 additions & 2 deletions app/x11_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ int BitsPerPixelForPixmapDepth(Display* display, int depth);
bool IsWindowVisible(XID window);
// Returns the bounds of |window|.
bool GetWindowRect(XID window, gfx::Rect* rect);
// Get the value of an int or string property. On success, true is returned and
// the value is stored in |value|.
// Get the value of an int, int array, or string property. On
// success, true is returned and the value is stored in |value|.
bool GetIntProperty(XID window, const std::string& property_name, int* value);
bool GetIntArrayProperty(XID window, const std::string& property_name,
std::vector<int>* value);
bool GetStringProperty(
XID window, const std::string& property_name, std::string* value);

Expand Down
9 changes: 9 additions & 0 deletions base/file_descriptor_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ struct FileDescriptor {
: fd(ifd),
auto_close(iauto_close) { }

bool operator==(const FileDescriptor& other) const {
return (fd == other.fd && auto_close == other.auto_close);
}

// A comparison operator so that we can use these as keys in a std::map.
bool operator<(const FileDescriptor& other) const {
return other.fd < fd;
}

int fd;
// If true, this file descriptor should be closed after it has been used. For
// example an IPC system might interpret this flag as indicating that the
Expand Down
12 changes: 8 additions & 4 deletions chrome/browser/browser_init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/first_run.h"
#include "chrome/browser/net/dns_global.h"
#include "chrome/browser/net/url_fixer_upper.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
#include "chrome/browser/pref_service.h"
#include "chrome/browser/profile.h"
Expand All @@ -30,13 +31,12 @@
#include "chrome/browser/sessions/session_restore.h"
#include "chrome/browser/sessions/session_service.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/tabs/pinned_tab_codec.h"
#include "chrome/browser/status_icons/status_tray_manager.h"
#include "chrome/browser/tab_contents/infobar_delegate.h"
#include "chrome/browser/tab_contents/navigation_controller.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/tab_contents_view.h"
#include "chrome/browser/net/url_fixer_upper.h"
#include "chrome/browser/status_icons/status_tray_manager.h"
#include "chrome/browser/tabs/pinned_tab_codec.h"
#include "chrome/browser/user_data_manager.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
Expand Down Expand Up @@ -68,14 +68,15 @@

#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/browser_notification_observers.h"
#include "chrome/browser/dom_ui/mediaplayer_ui.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/mount_library.h"
#include "chrome/browser/chromeos/cros/power_library.h"
#include "chrome/browser/chromeos/gview_request_interceptor.h"
#include "chrome/browser/chromeos/low_battery_observer.h"
#include "chrome/browser/chromeos/usb_mount_observer.h"
#include "chrome/browser/chromeos/wm_message_listener.h"
#include "chrome/browser/chromeos/wm_overview_controller.h"
#include "chrome/browser/dom_ui/mediaplayer_ui.h"
#endif

namespace {
Expand Down Expand Up @@ -398,6 +399,9 @@ bool BrowserInit::LaunchBrowser(
// of what window has focus.
chromeos::WmMessageListener::instance();

// Create the WmOverviewController so it can register with the listener.
chromeos::WmOverviewController::instance();

// Install the GView request interceptor that will redirect requests
// of compatible documents (PDF, etc) to the GView document viewer.
const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
Expand Down
16 changes: 15 additions & 1 deletion chrome/browser/chromeos/frame/browser_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <algorithm>
#include <string>
#include <vector>

#include "app/menus/simple_menu_model.h"
#include "app/theme_provider.h"
Expand Down Expand Up @@ -392,16 +393,29 @@ void BrowserView::Init() {
otr_avatar_icon_->SetImage(GetOTRAvatarIcon());
otr_avatar_icon_->SetID(VIEW_ID_OTR_AVATAR);
AddChildView(otr_avatar_icon_);

// Make sure the window is set to the right type.
std::vector<int> params;
params.push_back(browser()->tab_count());
params.push_back(browser()->selected_index());
WmIpc::instance()->SetWindowType(
GTK_WIDGET(frame()->GetWindow()->GetNativeWindow()),
WmIpc::WINDOW_TYPE_CHROME_TOPLEVEL,
&params);
}

void BrowserView::Show() {
bool was_visible = frame()->GetWindow()->IsVisible();
::BrowserView::Show();
if (!was_visible) {
// Have to update the tab count and selected index to reflect reality.
std::vector<int> params;
params.push_back(browser()->tab_count());
params.push_back(browser()->selected_index());
WmIpc::instance()->SetWindowType(
GTK_WIDGET(frame()->GetWindow()->GetNativeWindow()),
WmIpc::WINDOW_TYPE_CHROME_TOPLEVEL,
NULL);
&params);
}
}

Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/chromeos/panels/panel_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ IN_PROC_BROWSER_TEST_F(PanelTest, PanelOpenSmall) {
EXPECT_EQ(
WmIpc::WINDOW_TYPE_CHROME_PANEL_CONTENT,
WmIpc::instance()->GetWindowType(
GTK_WIDGET(new_browser->window()->GetNativeHandle())));
GTK_WIDGET(new_browser->window()->GetNativeHandle()), NULL));
}

// Large popups should open as new tab.
Expand Down
14 changes: 10 additions & 4 deletions chrome/browser/chromeos/wm_ipc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,18 @@ bool WmIpc::SetWindowType(GtkWidget* widget,
type_to_atom_[ATOM_CHROME_WINDOW_TYPE], values);
}

WmIpc::WindowType WmIpc::GetWindowType(GtkWidget* widget) {
int type;
if (x11_util::GetIntProperty(
WmIpc::WindowType WmIpc::GetWindowType(GtkWidget* widget,
std::vector<int>* params) {
std::vector<int> properties;
if (x11_util::GetIntArrayProperty(
x11_util::GetX11WindowFromGtkWidget(widget),
atom_to_string_[type_to_atom_[ATOM_CHROME_WINDOW_TYPE]],
&type)) {
&properties)) {
int type = properties.front();
if (params) {
params->clear();
params->insert(params->begin(), properties.begin() + 1, properties.end());
}
return static_cast<WindowType>(type);
} else {
return WINDOW_TYPE_UNKNOWN;
Expand Down
95 changes: 36 additions & 59 deletions chrome/browser/chromeos/wm_ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,14 @@ class WmIpc {
WINDOW_TYPE_UNKNOWN = 0,

// A top-level Chrome window.
// param[0]: The number of tabs currently in this Chrome window.
// param[1]: The index of the currently selected tab in this
// Chrome window.
WINDOW_TYPE_CHROME_TOPLEVEL,

// A window showing scaled-down views of all of the tabs within a
// Chrome window.
WINDOW_TYPE_CHROME_TAB_SUMMARY,

// A tab that's been detached from a Chrome window and is currently
// being dragged.
// param[0]: Cursor's initial X position at the start of the drag
// param[1]: Cursor's initial Y position
// param[2]: X component of cursor's offset from upper-left corner of
// tab at start of drag
// param[3]: Y component of cursor's offset
WINDOW_TYPE_CHROME_FLOATING_TAB,
// Vestiges of the old windows-across-the-bottom overview mode.
DEPRECATED_WINDOW_TYPE_CHROME_TAB_SUMMARY,
DEPRECATED_WINDOW_TYPE_CHROME_FLOATING_TAB,

// The contents of a popup window.
// param[0]: X ID of associated titlebar, which must be mapped before
Expand All @@ -66,8 +60,8 @@ class WmIpc {
// drawn above the panel when it's expanded.
WINDOW_TYPE_CHROME_PANEL_TITLEBAR,

// A small window that when clicked creates a new browser window.
WINDOW_TYPE_CREATE_BROWSER_WINDOW,
// Vestiges of an earlier UI design.
DEPRECATED_WINDOW_TYPE_CREATE_BROWSER_WINDOW,

// A Chrome info bubble (e.g. the bookmark bubble). These are
// transient RGBA windows; we skip the usual transient behavior of
Expand All @@ -76,8 +70,7 @@ class WmIpc {

// A window showing a view of a tab within a Chrome window.
// param[0]: X ID of toplevel window that owns it.
// param[1]: index of this tab in the tab order (range is 0 to
// sum of all tabs in all browsers).
// param[1]: index of this tab in the toplevel window that owns it.
WINDOW_TYPE_CHROME_TAB_SNAPSHOT,

// The following types are used for the windows that represent a user that
Expand Down Expand Up @@ -118,27 +111,10 @@ class WmIpc {
enum Type {
UNKNOWN = 0,

// Notify Chrome when a floating tab has entered or left a tab
// summary window. Sent to the summary window.
// param[0]: X ID of the floating tab window
// param[1]: state (0 means left, 1 means entered or currently in)
// param[2]: X coordinate relative to summary window
// param[3]: Y coordinate
CHROME_NOTIFY_FLOATING_TAB_OVER_TAB_SUMMARY,

// Notify Chrome when a floating tab has entered or left a top-level
// window. Sent to the window being entered/left.
// param[0]: X ID of the floating tab window
// param[1]: state (0 means left, 1 means entered)
CHROME_NOTIFY_FLOATING_TAB_OVER_TOPLEVEL,

// Instruct a top-level Chrome window to change the visibility of its
// tab summary window.
// param[0]: desired visibility (0 means hide, 1 means show)
// param[1]: X position (relative to the left edge of the root
// window) of the center of the top-level window. Only
// relevant for "show" messages
CHROME_SET_TAB_SUMMARY_VISIBILITY,
// Vestiges of the old windows-across-the-bottom overview mode.
DEPRECATED_CHROME_NOTIFY_FLOATING_TAB_OVER_TAB_SUMMARY,
DEPRECATED_CHROME_NOTIFY_FLOATING_TAB_OVER_TOPLEVEL,
DEPRECATED_CHROME_SET_TAB_SUMMARY_VISIBILITY,

// Tell the WM to collapse or expand a panel.
// param[0]: X ID of the panel window
Expand All @@ -148,16 +124,12 @@ class WmIpc {
// Notify Chrome that the panel state has changed. Sent to the panel
// window.
// param[0]: new state (0 means collapsed, 1 means expanded)
// TODO: Deprecate this; Chrome can just watch for changes to the
// _CHROME_STATE property to get the same information.
CHROME_NOTIFY_PANEL_STATE,

// Instruct the WM to move a floating tab. The passed-in position is
// that of the cursor; the tab's composited window is displaced based
// on the cursor's offset from the upper-left corner of the tab at
// the start of the drag.
// param[0]: X ID of the floating tab window
// param[1]: X coordinate to which the tab should be moved
// param[2]: Y coordinate
WM_MOVE_FLOATING_TAB,
// From the old windows-across-the-bottom overview mode.
DEPRECATED_WM_MOVE_FLOATING_TAB,

// Notify the WM that a panel has been dragged.
// param[0]: X ID of the panel's content window
Expand All @@ -180,18 +152,21 @@ class WmIpc {
// param[0]: X ID of the panel's content window
WM_NOTIFY_PANEL_DRAG_COMPLETE,

// Deprecated. Send a _NET_ACTIVE_WINDOW client message to focus a window
// instead (e.g. using gtk_window_present()).
// Deprecated. Send a _NET_ACTIVE_WINDOW client message to focus a
// window instead (e.g. using gtk_window_present()).
DEPRECATED_WM_FOCUS_WINDOW,

// Notify Chrome that the layout mode (for example, overview or
// focused) has changed.
// param[0]: new mode (0 means focused, 1 means overview)
// active) has changed. Since overview mode can be "cancelled"
// (user hits escape to revert), we have an extra parameter to
// indicate this.
// param[0]: new mode (0 means active mode, 1 means overview mode)
// param[1]: was mode cancelled? (0 = no, 1 = yes)
CHROME_NOTIFY_LAYOUT_MODE,

// Instruct the WM to enter overview mode.
// Deprecated. Instruct the WM to enter overview mode.
// param[0]: X ID of the window to show the tab overview for.
WM_SWITCH_TO_OVERVIEW_MODE,
DEPRECATED_WM_SWITCH_TO_OVERVIEW_MODE,

// Let the WM know which version of this file Chrome is using. It's
// difficult to make changes synchronously to Chrome and the WM (our
Expand All @@ -218,11 +193,11 @@ class WmIpc {
// param[0]: version of this protocol currently supported
WM_NOTIFY_IPC_VERSION,

// Notify Chrome when a tab snapshot has been 'magnified' in the
// overview. Sent to the top level window.
// param[0]: X ID of the tab snapshot window
// param[1]: state (0 means end magnify, 1 means begin magnify)
CHROME_NOTIFY_TAB_SNAPSHOT_MAGNIFY,
// Notify Chrome when a tab has been selected in the overview.
// Sent to the toplevel window associated with the magnified
// tab.
// param[0]: tab index of newly selected tab.
CHROME_NOTIFY_TAB_SELECT,

// Forces the window manager to hide the login windows.
WM_HIDE_LOGIN,
Expand Down Expand Up @@ -295,9 +270,11 @@ class WmIpc {
WindowType type,
const std::vector<int>* params);

// Gets the type of the window. The caller is responsible for trapping
// errors from the X server.
WmIpc::WindowType GetWindowType(GtkWidget* widget);
// Gets the type of the window, and any associated parameters. The
// caller is responsible for trapping errors from the X server. If
// the parameters are not interesting to the caller, NULL may be
// passed for |params|.
WmIpc::WindowType GetWindowType(GtkWidget* widget, std::vector<int>* params);

// Sends a message to the WM.
void SendMessage(const Message& msg);
Expand Down
Loading

0 comments on commit d65adb1

Please sign in to comment.