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

Side by Side Diff: views/widget/wm_ipc.cc

Issue 8604012: move chromeos bubble setup code to window.cc (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: move functionality of wm ipc out of browser so that views/bubble can use it. Created 9 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 unified diff | Download patch | Annotate | Revision Log
« ui/views/bubble/bubble_delegate.h ('K') | « views/widget/wm_ipc.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/legacy_window_manager/wm_ipc.h" 5 #include "views/widget/wm_ipc.h"
6 6
7 #include <gdk/gdkx.h> 7 #include <gdk/gdkx.h>
8 extern "C" { 8 extern "C" {
9 #include <X11/Xatom.h> 9 #include <X11/Xatom.h>
10 #include <X11/Xlib.h> 10 #include <X11/Xlib.h>
11 } 11 }
12 12
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "chrome/common/chrome_notification_types.h"
17 #include "content/public/browser/notification_service.h"
18 #include "ui/base/x/x11_util.h" 16 #include "ui/base/x/x11_util.h"
19 #include "ui/gfx/rect.h" 17 #include "ui/gfx/rect.h"
20 18
21 using std::map; 19 using std::map;
22 using std::string; 20 using std::string;
23 21
22 namespace views {
23
24 namespace chromeos { 24 namespace chromeos {
25 25
26 namespace { 26 namespace {
27 27
28 // A value from the Atom enum and the actual name that should be used to 28 // A value from the Atom enum and the actual name that should be used to
29 // look up its ID on the X server. 29 // look up its ID on the X server.
30 struct AtomInfo { 30 struct AtomInfo {
31 WmIpc::AtomType atom; 31 WmIpc::AtomType atom;
32 const char* name; 32 const char* name;
33 }; 33 };
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 atom_to_string_.find(atom_it->second); 91 atom_to_string_.find(atom_it->second);
92 DCHECK(name_it != atom_to_string_.end()) 92 DCHECK(name_it != atom_to_string_.end())
93 << "Unknown atom " << atom_it->second << " for AtomType " << type; 93 << "Unknown atom " << atom_it->second << " for AtomType " << type;
94 if (name_it == atom_to_string_.end()) 94 if (name_it == atom_to_string_.end())
95 return ""; 95 return "";
96 96
97 return name_it->second; 97 return name_it->second;
98 } 98 }
99 99
100 bool WmIpc::SetWindowType(GtkWidget* widget, 100 bool WmIpc::SetWindowType(GtkWidget* widget,
101 WmIpcWindowType type, 101 ::chromeos::WmIpcWindowType type,
102 const std::vector<int>* params) { 102 const std::vector<int>* params) {
103 std::vector<int> values; 103 std::vector<int> values;
104 values.push_back(type); 104 values.push_back(type);
105 if (params) 105 if (params)
106 values.insert(values.end(), params->begin(), params->end()); 106 values.insert(values.end(), params->begin(), params->end());
107 const Atom atom = type_to_atom_[ATOM_CHROME_WINDOW_TYPE]; 107 const Atom atom = type_to_atom_[ATOM_CHROME_WINDOW_TYPE];
108 return SetIntArrayProperty(ui::GetX11WindowFromGtkWidget(widget), 108 return SetIntArrayProperty(ui::GetX11WindowFromGtkWidget(widget),
109 atom, atom, values); 109 atom, atom, values);
110 } 110 }
111 111
112 WmIpcWindowType WmIpc::GetWindowType(GtkWidget* widget, 112 ::chromeos::WmIpcWindowType WmIpc::GetWindowType(GtkWidget* widget,
113 std::vector<int>* params) { 113 std::vector<int>* params) {
114 std::vector<int> properties; 114 std::vector<int> properties;
115 if (ui::GetIntArrayProperty( 115 if (ui::GetIntArrayProperty(
116 ui::GetX11WindowFromGtkWidget(widget), 116 ui::GetX11WindowFromGtkWidget(widget),
117 GetAtomName(ATOM_CHROME_WINDOW_TYPE), 117 GetAtomName(ATOM_CHROME_WINDOW_TYPE),
118 &properties)) { 118 &properties)) {
119 int type = properties.front(); 119 int type = properties.front();
120 if (params) { 120 if (params) {
121 params->clear(); 121 params->clear();
122 params->insert(params->begin(), properties.begin() + 1, properties.end()); 122 params->insert(params->begin(), properties.begin() + 1, properties.end());
123 } 123 }
124 return static_cast<WmIpcWindowType>(type); 124 return static_cast< ::chromeos::WmIpcWindowType>(type);
125 } else { 125 } else {
126 return WM_IPC_WINDOW_UNKNOWN; 126 return ::chromeos::WM_IPC_WINDOW_UNKNOWN;
127 } 127 }
128 } 128 }
129 129
130 bool WmIpc::GetWindowState(GtkWidget* widget, 130 bool WmIpc::GetWindowState(GtkWidget* widget,
131 std::set<WmIpc::AtomType>* atom_types) { 131 std::set<WmIpc::AtomType>* atom_types) {
132 atom_types->clear(); 132 atom_types->clear();
133 133
134 std::vector<Atom> atoms; 134 std::vector<Atom> atoms;
135 if (!ui::GetAtomArrayProperty( 135 if (!ui::GetAtomArrayProperty(
136 ui::GetX11WindowFromGtkWidget(widget), 136 ui::GetX11WindowFromGtkWidget(widget),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 if (wm_message_atom_ != gdk_x11_atom_to_xatom(event.message_type)) 175 if (wm_message_atom_ != gdk_x11_atom_to_xatom(event.message_type))
176 return false; 176 return false;
177 177
178 if (event.data_format != 32) { 178 if (event.data_format != 32) {
179 DLOG(WARNING) << "Ignoring ClientEventMessage with invalid bit " 179 DLOG(WARNING) << "Ignoring ClientEventMessage with invalid bit "
180 << "format " << event.data_format 180 << "format " << event.data_format
181 << " (expected 32-bit values)"; 181 << " (expected 32-bit values)";
182 return false; 182 return false;
183 } 183 }
184 184
185 msg->set_type(static_cast<WmIpcMessageType>(event.data.l[0])); 185 msg->set_type(static_cast< ::chromeos::WmIpcMessageType>(event.data.l[0]));
186 if (msg->type() < 0) { 186 if (msg->type() < 0) {
187 DLOG(WARNING) << "Ignoring ClientEventMessage with invalid message " 187 DLOG(WARNING) << "Ignoring ClientEventMessage with invalid message "
188 << "type " << msg->type(); 188 << "type " << msg->type();
189 return false; 189 return false;
190 } 190 }
191 191
192 // XClientMessageEvent only gives us five 32-bit items, and we're using 192 // XClientMessageEvent only gives us five 32-bit items, and we're using
193 // the first one for our message type. 193 // the first one for our message type.
194 DCHECK_LE(msg->max_params(), 4); 194 DCHECK_LE(msg->max_params(), 4);
195 for (int i = 0; i < msg->max_params(); ++i) 195 for (int i = 0; i < msg->max_params(); ++i)
196 msg->set_param(i, event.data.l[i+1]); // l[0] contains message type 196 msg->set_param(i, event.data.l[i+1]); // l[0] contains message type
197 197
198 return true; 198 return true;
199 } 199 }
200 200
201 void WmIpc::HandleNonChromeClientMessageEvent(const GdkEventClient& event) { 201 void WmIpc::HandleNonChromeClientMessageEvent(const GdkEventClient& event) {
202 // Only do these lookups once; they should never change. 202 // Only do these lookups once; they should never change.
203 static GdkAtom manager_gdk_atom = 203 static GdkAtom manager_gdk_atom =
204 gdk_x11_xatom_to_atom(type_to_atom_[ATOM_MANAGER]); 204 gdk_x11_xatom_to_atom(type_to_atom_[ATOM_MANAGER]);
205 static Atom wm_s0_atom = type_to_atom_[ATOM_WM_S0]; 205 static Atom wm_s0_atom = type_to_atom_[ATOM_WM_S0];
206 206
207 if (event.message_type == manager_gdk_atom && 207 if (event.message_type == manager_gdk_atom &&
208 static_cast<Atom>(event.data.l[1]) == wm_s0_atom) { 208 static_cast<Atom>(event.data.l[1]) == wm_s0_atom) {
209 InitWmInfo(); 209 InitWmInfo();
210 } 210 }
211 } 211 }
212 212
213 void WmIpc::HandleRootWindowPropertyEvent(const GdkEventProperty& event) {
214 static GdkAtom layout_mode_gdk_atom =
215 gdk_x11_xatom_to_atom(type_to_atom_[ATOM_CHROME_LAYOUT_MODE]);
216
217 if (event.atom == layout_mode_gdk_atom)
218 FetchLayoutModeProperty();
219 }
220
221 void WmIpc::SetLoggedInProperty(bool logged_in) { 213 void WmIpc::SetLoggedInProperty(bool logged_in) {
222 std::vector<int> values; 214 std::vector<int> values;
223 values.push_back(static_cast<int>(logged_in)); 215 values.push_back(static_cast<int>(logged_in));
224 const Atom atom = type_to_atom_[ATOM_CHROME_LOGGED_IN]; 216 const Atom atom = type_to_atom_[ATOM_CHROME_LOGGED_IN];
225 SetIntArrayProperty(gdk_x11_get_default_root_xwindow(), atom, atom, values); 217 SetIntArrayProperty(gdk_x11_get_default_root_xwindow(), atom, atom, values);
226 } 218 }
227 219
228 void WmIpc::SetStatusBoundsProperty(GtkWidget* widget, 220 void WmIpc::SetStatusBoundsProperty(GtkWidget* widget,
229 const gfx::Rect& bounds) { 221 const gfx::Rect& bounds) {
230 std::vector<int> values; 222 std::vector<int> values;
231 values.push_back(bounds.x()); 223 values.push_back(bounds.x());
232 values.push_back(bounds.y()); 224 values.push_back(bounds.y());
233 values.push_back(bounds.width()); 225 values.push_back(bounds.width());
234 values.push_back(bounds.height()); 226 values.push_back(bounds.height());
235 SetIntArrayProperty(ui::GetX11WindowFromGtkWidget(widget), 227 SetIntArrayProperty(ui::GetX11WindowFromGtkWidget(widget),
236 type_to_atom_[ATOM_CHROME_STATUS_BOUNDS], 228 type_to_atom_[ATOM_CHROME_STATUS_BOUNDS],
237 XA_CARDINAL, 229 XA_CARDINAL,
238 values); 230 values);
239 } 231 }
240 232
241 void WmIpc::NotifyAboutSignout() { 233 void WmIpc::NotifyAboutSignout() {
242 Message msg(chromeos::WM_IPC_MESSAGE_WM_NOTIFY_SIGNING_OUT); 234 Message msg(::chromeos::WM_IPC_MESSAGE_WM_NOTIFY_SIGNING_OUT);
243 SendMessage(msg); 235 SendMessage(msg);
244 XFlush(ui::GetXDisplay()); 236 XFlush(ui::GetXDisplay());
245 } 237 }
246 238
247 WmIpc::WmIpc() 239 WmIpc::WmIpc()
248 : wm_message_atom_(0), 240 : wm_message_atom_(0),
249 wm_(0), 241 wm_(0) {
250 layout_mode_(WM_IPC_LAYOUT_MAXIMIZED) {
251 scoped_array<char*> names(new char*[kNumAtoms]); 242 scoped_array<char*> names(new char*[kNumAtoms]);
252 scoped_array<Atom> atoms(new Atom[kNumAtoms]); 243 scoped_array<Atom> atoms(new Atom[kNumAtoms]);
253 244
254 for (int i = 0; i < kNumAtoms; ++i) { 245 for (int i = 0; i < kNumAtoms; ++i) {
255 // Need to const_cast because XInternAtoms() wants a char**. 246 // Need to const_cast because XInternAtoms() wants a char**.
256 names[i] = const_cast<char*>(kAtomInfos[i].name); 247 names[i] = const_cast<char*>(kAtomInfos[i].name);
257 } 248 }
258 249
259 XInternAtoms(ui::GetXDisplay(), names.get(), kNumAtoms, 250 XInternAtoms(ui::GetXDisplay(), names.get(), kNumAtoms,
260 False, // only_if_exists 251 False, // only_if_exists
261 atoms.get()); 252 atoms.get());
262 253
263 for (int i = 0; i < kNumAtoms; ++i) { 254 for (int i = 0; i < kNumAtoms; ++i) {
264 type_to_atom_[kAtomInfos[i].atom] = atoms[i]; 255 type_to_atom_[kAtomInfos[i].atom] = atoms[i];
265 atom_to_type_[atoms[i]] = kAtomInfos[i].atom; 256 atom_to_type_[atoms[i]] = kAtomInfos[i].atom;
266 atom_to_string_[atoms[i]] = kAtomInfos[i].name; 257 atom_to_string_[atoms[i]] = kAtomInfos[i].name;
267 } 258 }
268 259
269 wm_message_atom_ = type_to_atom_[ATOM_CHROME_WM_MESSAGE]; 260 wm_message_atom_ = type_to_atom_[ATOM_CHROME_WM_MESSAGE];
270 261
271 // Make sure that we're selecting structure changes on the root window; 262 // Make sure that we're selecting structure changes on the root window;
272 // the window manager uses StructureNotifyMask when sending the ClientMessage 263 // the window manager uses StructureNotifyMask when sending the ClientMessage
273 // event to announce that it's taken the manager selection. 264 // event to announce that it's taken the manager selection.
274 GdkWindow* root = gdk_get_default_root_window(); 265 GdkWindow* root = gdk_get_default_root_window();
275 GdkEventMask event_mask = gdk_window_get_events(root); 266 GdkEventMask event_mask = gdk_window_get_events(root);
276 gdk_window_set_events( 267 gdk_window_set_events(
277 root, 268 root,
278 static_cast<GdkEventMask>( 269 static_cast<GdkEventMask>(
279 event_mask | GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK)); 270 event_mask | GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK));
280
281 InitWmInfo(); 271 InitWmInfo();
282 FetchLayoutModeProperty();
283 } 272 }
284 273
285 WmIpc::~WmIpc() {} 274 WmIpc::~WmIpc() {}
286 275
287 void WmIpc::InitWmInfo() { 276 void WmIpc::InitWmInfo() {
288 wm_ = XGetSelectionOwner(ui::GetXDisplay(), type_to_atom_[ATOM_WM_S0]); 277 wm_ = XGetSelectionOwner(ui::GetXDisplay(), type_to_atom_[ATOM_WM_S0]);
289 278
290 // Let the window manager know which version of the IPC messages we support. 279 // Let the window manager know which version of the IPC messages we support.
291 Message msg(chromeos::WM_IPC_MESSAGE_WM_NOTIFY_IPC_VERSION); 280 Message msg(::chromeos::WM_IPC_MESSAGE_WM_NOTIFY_IPC_VERSION);
292 // TODO: The version number is the latest listed in wm_ipc.h -- 281 // TODO: The version number is the latest listed in wm_ipc.h --
293 // ideally, once this header is shared between Chrome and the Chrome OS window 282 // ideally, once this header is shared between Chrome and the Chrome OS window
294 // manager, we'll just define the version statically in the header. 283 // manager, we'll just define the version statically in the header.
295 msg.set_param(0, 1); 284 msg.set_param(0, 1);
296 SendMessage(msg); 285 SendMessage(msg);
297 } 286 }
298 287
299 void WmIpc::FetchLayoutModeProperty() { 288 } // namespace chromeos
300 int value = 0;
301 if (ui::GetIntProperty(
302 gdk_x11_get_default_root_xwindow(),
303 GetAtomName(ATOM_CHROME_LAYOUT_MODE),
304 &value)) {
305 layout_mode_ = static_cast<WmIpcLayoutMode>(value);
306 content::NotificationService::current()->Notify(
307 chrome::NOTIFICATION_LAYOUT_MODE_CHANGED,
308 content::Source<WmIpc>(this),
309 content::Details<WmIpcLayoutMode>(&layout_mode_));
310 } else {
311 DLOG(WARNING) << "Missing _CHROME_LAYOUT_MODE property on root window";
312 }
313 }
314 289
315 } // namespace chromeos 290 } // namespace views
OLDNEW
« ui/views/bubble/bubble_delegate.h ('K') | « views/widget/wm_ipc.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698