summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-12 14:34:39 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-12 14:34:39 +0000
commit8a9b6a53699c2702da395ad4aaef131921f55e71 (patch)
tree7c0e47110cb7fa6596e535d38d00d9723202f018
parent3a5e0dd29d2fb60385c3f664f81f778bd0cf8024 (diff)
downloadchromium_src-8a9b6a53699c2702da395ad4aaef131921f55e71.zip
chromium_src-8a9b6a53699c2702da395ad4aaef131921f55e71.tar.gz
chromium_src-8a9b6a53699c2702da395ad4aaef131921f55e71.tar.bz2
Adds wiring for tab overview.
BUG=none TEST=none Review URL: http://codereview.chromium.org/125020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18267 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/views/tabs/tab_overview_types.cc139
-rw-r--r--chrome/browser/views/tabs/tab_overview_types.h171
2 files changed, 310 insertions, 0 deletions
diff --git a/chrome/browser/views/tabs/tab_overview_types.cc b/chrome/browser/views/tabs/tab_overview_types.cc
new file mode 100644
index 0000000..ee39362
--- /dev/null
+++ b/chrome/browser/views/tabs/tab_overview_types.cc
@@ -0,0 +1,139 @@
+// 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/views/tabs/tab_overview_types.h"
+
+#include <gdk/gdkx.h>
+extern "C" {
+#include <X11/Xlib.h>
+}
+
+#include "base/logging.h"
+#include "base/singleton.h"
+#include "base/scoped_ptr.h"
+#include "chrome/common/x11_util.h"
+
+namespace {
+
+// A value from the Atom enum and the actual name that should be used to
+// look up its ID on the X server.
+struct AtomInfo {
+ TabOverviewTypes::AtomType atom;
+ const char* name;
+};
+
+// Each value from the Atom enum must be present here.
+static const AtomInfo kAtomInfos[] = {
+ { TabOverviewTypes::ATOM_CHROME_WINDOW_TYPE,
+ "_CHROME_WINDOW_TYPE" },
+ { TabOverviewTypes::ATOM_CHROME_WM_MESSAGE,
+ "_CHROME_WM_MESSAGE" },
+ { TabOverviewTypes::ATOM_MANAGER,
+ "MANAGER" },
+ { TabOverviewTypes::ATOM_NET_SUPPORTING_WM_CHECK,
+ "_NET_SUPPORTING_WM_CHECK" },
+ { TabOverviewTypes::ATOM_NET_WM_NAME,
+ "_NET_WM_NAME" },
+ { TabOverviewTypes::ATOM_PRIMARY,
+ "PRIMARY" },
+ { TabOverviewTypes::ATOM_STRING,
+ "STRING" },
+ { TabOverviewTypes::ATOM_UTF8_STRING,
+ "UTF8_STRING" },
+ { TabOverviewTypes::ATOM_WM_NORMAL_HINTS,
+ "WM_NORMAL_HINTS" },
+ { TabOverviewTypes::ATOM_WM_S0,
+ "WM_S0" },
+ { TabOverviewTypes::ATOM_WM_STATE,
+ "WM_STATE" },
+ { TabOverviewTypes::ATOM_WM_TRANSIENT_FOR,
+ "WM_TRANSIENT_FOR" },
+};
+
+bool SetIntProperty(XID xid, Atom xatom, const std::vector<int>& values) {
+ DCHECK(!values.empty());
+
+ // TODO: Trap errors and return false on failure.
+ XChangeProperty(x11_util::GetXDisplay(),
+ xid,
+ xatom,
+ xatom,
+ 32, // size in bits of items in 'value'
+ PropModeReplace,
+ reinterpret_cast<const unsigned char*>(&values.front()),
+ values.size()); // num items
+ XFlush(x11_util::GetXDisplay());
+ return true;
+}
+
+} // namespace
+
+// static
+TabOverviewTypes* TabOverviewTypes::instance() {
+ static TabOverviewTypes* instance = NULL;
+ if (!instance)
+ instance = Singleton<TabOverviewTypes>::get();
+ return instance;
+}
+
+bool TabOverviewTypes::SetWindowType(
+ GtkWidget* widget,
+ WindowType type,
+ const std::vector<int>* params) {
+ std::vector<int> values;
+ values.push_back(type);
+ if (params)
+ values.insert(values.end(), params->begin(), params->end());
+ return SetIntProperty(x11_util::GetX11WindowFromGtkWidget(widget),
+ type_to_atom_[ATOM_CHROME_WINDOW_TYPE], values);
+}
+
+bool TabOverviewTypes::DecodeMessage(const GdkEventClient& event,
+ Message* msg) {
+ if (wm_message_atom_ != gdk_x11_atom_to_xatom(event.message_type))
+ return false;
+
+ if (event.data_format != 32) {
+ DLOG(WARNING) << "Ignoring ClientEventMessage with invalid bit "
+ << "format " << event.data_format
+ << " (expected 32-bit values)";
+ return false;
+ }
+
+ msg->set_type(static_cast<Message::Type>(event.data.l[0]));
+ if (msg->type() < 0 || msg->type() >= Message::kNumTypes) {
+ DLOG(WARNING) << "Ignoring ClientEventMessage with invalid message "
+ << "type " << msg->type();
+ return false;
+ }
+
+ // XClientMessageEvent only gives us five 32-bit items, and we're using
+ // the first one for our message type.
+ DCHECK_LE(msg->max_params(), 4);
+ for (int i = 0; i < msg->max_params(); ++i)
+ msg->set_param(i, event.data.l[i+1]); // l[0] contains message type
+
+ return true;
+}
+
+TabOverviewTypes::TabOverviewTypes() {
+ scoped_array<char*> names(new char*[kNumAtoms]);
+ scoped_array<Atom> atoms(new Atom[kNumAtoms]);
+
+ for (int i = 0; i < kNumAtoms; ++i) {
+ // Need to const_cast because XInternAtoms() wants a char**.
+ names[i] = const_cast<char*>(kAtomInfos[i].name);
+ }
+
+ XInternAtoms(x11_util::GetXDisplay(), names.get(), kNumAtoms,
+ False, // only_if_exists
+ atoms.get());
+
+ for (int i = 0; i < kNumAtoms; ++i) {
+ type_to_atom_[kAtomInfos[i].atom] = atoms[i];
+ atom_to_string_[atoms[i]] = kAtomInfos[i].name;
+ }
+
+ wm_message_atom_ = type_to_atom_[ATOM_CHROME_WM_MESSAGE];
+}
diff --git a/chrome/browser/views/tabs/tab_overview_types.h b/chrome/browser/views/tabs/tab_overview_types.h
new file mode 100644
index 0000000..b643706
--- /dev/null
+++ b/chrome/browser/views/tabs/tab_overview_types.h
@@ -0,0 +1,171 @@
+// 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.
+
+#ifndef CHROME_BROWSER_VIEWS_TABS_TAB_OVERVIEW_TYPES_H_
+#define CHROME_BROWSER_VIEWS_TABS_TAB_OVERVIEW_TYPES_H_
+
+#include <gtk/gtk.h>
+#include <map>
+#include <string>
+#include <vector>
+
+#include "base/logging.h"
+#include "base/singleton.h"
+
+typedef unsigned long Atom;
+
+// TODO(sky): move and rename.
+class TabOverviewTypes {
+ public:
+ enum AtomType {
+ ATOM_CHROME_WINDOW_TYPE = 0,
+ ATOM_CHROME_WM_MESSAGE,
+ ATOM_MANAGER,
+ ATOM_NET_SUPPORTING_WM_CHECK,
+ ATOM_NET_WM_NAME,
+ ATOM_PRIMARY,
+ ATOM_STRING,
+ ATOM_UTF8_STRING,
+ ATOM_WM_NORMAL_HINTS,
+ ATOM_WM_S0,
+ ATOM_WM_STATE,
+ ATOM_WM_TRANSIENT_FOR,
+ kNumAtoms,
+ };
+
+ enum WindowType {
+ WINDOW_TYPE_UNKNOWN = 0,
+
+ // A top-level 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,
+
+ kNumWindowTypes,
+ };
+
+ struct Message {
+ public:
+ enum Type {
+ UNKNOWN = 0,
+
+ // 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)
+ CHROME_SET_TAB_SUMMARY_VISIBILITY,
+
+ // 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,
+
+ // 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,
+
+ // 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,
+
+ kNumTypes,
+ };
+
+ Message() {
+ Init(UNKNOWN);
+ }
+ Message(Type type) {
+ Init(type);
+ }
+
+ Type type() const { return type_; }
+ void set_type(Type type) { type_ = type; }
+
+ inline int max_params() const {
+ return arraysize(params_);
+ }
+ long param(int index) const {
+ DCHECK_GE(index, 0);
+ DCHECK_LT(index, max_params());
+ return params_[index];
+ }
+ void set_param(int index, long value) {
+ DCHECK_GE(index, 0);
+ DCHECK_LT(index, max_params());
+ params_[index] = value;
+ }
+
+ private:
+ // Common initialization code shared between constructors.
+ void Init(Type type) {
+ set_type(type);
+ for (int i = 0; i < max_params(); ++i) {
+ set_param(i, 0);
+ }
+ }
+
+ // Type of message that was sent.
+ Type type_;
+
+ // Type-specific data. This is bounded by the number of 32-bit values
+ // that we can pack into a ClientMessageEvent -- it holds five, but we
+ // use the first one to store the message type.
+ long params_[4];
+ };
+
+ // Returns the single instance of TabOverviewTypes.
+ static TabOverviewTypes* instance();
+
+ // Get or set a property describing a window's type. Type-specific
+ // parameters may also be supplied ('params' is mandatory for
+ // GetWindowType() but optional for SetWindowType()). The caller is
+ // responsible for trapping errors from the X server.
+ // TODO: Trap these ourselves.
+ bool SetWindowType(GtkWidget* widget,
+ WindowType type,
+ const std::vector<int>* params);
+
+ // If |event| is a valid Message it is decoded into |msg| and true is
+ // returned. If false is returned, |event| is not a valid Message.
+ bool DecodeMessage(const GdkEventClient& event, Message* msg);
+
+ private:
+ friend struct DefaultSingletonTraits<TabOverviewTypes>;
+
+ TabOverviewTypes();
+
+ // Maps from our Atom enum to the X server's atom IDs and from the
+ // server's IDs to atoms' string names. These maps aren't necessarily in
+ // sync; 'atom_to_xatom_' is constant after the constructor finishes but
+ // GetName() caches additional string mappings in 'xatom_to_string_'.
+ std::map<AtomType, Atom> type_to_atom_;
+ std::map<Atom, std::string> atom_to_string_;
+
+ // Cached value of type_to_atom_[ATOM_CHROME_WM_MESSAGE].
+ Atom wm_message_atom_;
+
+ DISALLOW_COPY_AND_ASSIGN(TabOverviewTypes);
+};
+
+#endif // CHROME_BROWSER_VIEWS_TABS_TAB_OVERVIEW_TYPES_H_