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

Side by Side Diff: ui/base/x/x11_util.cc

Issue 853033002: More delete + gfx_unittests (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Fix android trybots Created 5 years, 11 months 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
« no previous file with comments | « ui/base/x/x11_util.h ('k') | ui/gfx/BUILD.gn » ('j') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // This file defines utility functions for X11 (Linux only). This code has been 5 // This file defines utility functions for X11 (Linux only). This code has been
6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support 6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support
7 // remains woefully incomplete. 7 // remains woefully incomplete.
8 8
9 #include "ui/base/x/x11_util.h" 9 #include "ui/base/x/x11_util.h"
10 10
(...skipping 18 matching lines...) Expand all
29 #include "base/message_loop/message_loop.h" 29 #include "base/message_loop/message_loop.h"
30 #include "base/metrics/histogram.h" 30 #include "base/metrics/histogram.h"
31 #include "base/strings/string_number_conversions.h" 31 #include "base/strings/string_number_conversions.h"
32 #include "base/strings/string_util.h" 32 #include "base/strings/string_util.h"
33 #include "base/strings/stringprintf.h" 33 #include "base/strings/stringprintf.h"
34 #include "base/sys_byteorder.h" 34 #include "base/sys_byteorder.h"
35 #include "base/threading/thread.h" 35 #include "base/threading/thread.h"
36 #include "skia/ext/image_operations.h" 36 #include "skia/ext/image_operations.h"
37 #include "third_party/skia/include/core/SkBitmap.h" 37 #include "third_party/skia/include/core/SkBitmap.h"
38 #include "third_party/skia/include/core/SkPostConfig.h" 38 #include "third_party/skia/include/core/SkPostConfig.h"
39 #include "ui/base/x/x11_menu_list.h"
40 #include "ui/base/x/x11_util_internal.h" 39 #include "ui/base/x/x11_util_internal.h"
41 #include "ui/events/event_utils.h" 40 #include "ui/events/event_utils.h"
42 #include "ui/events/keycodes/keyboard_code_conversion_x.h" 41 #include "ui/events/keycodes/keyboard_code_conversion_x.h"
43 #include "ui/events/x/device_data_manager_x11.h" 42 #include "ui/events/x/device_data_manager_x11.h"
44 #include "ui/events/x/touch_factory_x11.h" 43 #include "ui/events/x/touch_factory_x11.h"
45 #include "ui/gfx/geometry/insets.h" 44 #include "ui/gfx/geometry/insets.h"
46 #include "ui/gfx/geometry/point.h" 45 #include "ui/gfx/geometry/point.h"
47 #include "ui/gfx/geometry/point_conversions.h" 46 #include "ui/gfx/geometry/point_conversions.h"
48 #include "ui/gfx/geometry/rect.h" 47 #include "ui/gfx/geometry/rect.h"
49 #include "ui/gfx/geometry/size.h" 48 #include "ui/gfx/geometry/size.h"
(...skipping 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 // Returns true if |window| is a named window. 1076 // Returns true if |window| is a named window.
1078 bool IsWindowNamed(XID window) { 1077 bool IsWindowNamed(XID window) {
1079 XTextProperty prop; 1078 XTextProperty prop;
1080 if (!XGetWMName(gfx::GetXDisplay(), window, &prop) || !prop.value) 1079 if (!XGetWMName(gfx::GetXDisplay(), window, &prop) || !prop.value)
1081 return false; 1080 return false;
1082 1081
1083 XFree(prop.value); 1082 XFree(prop.value);
1084 return true; 1083 return true;
1085 } 1084 }
1086 1085
1087 bool EnumerateChildren(EnumerateWindowsDelegate* delegate, XID window,
1088 const int max_depth, int depth) {
1089 if (depth > max_depth)
1090 return false;
1091
1092 std::vector<XID> windows;
1093 std::vector<XID>::iterator iter;
1094 if (depth == 0) {
1095 XMenuList::GetInstance()->InsertMenuWindowXIDs(&windows);
1096 // Enumerate the menus first.
1097 for (iter = windows.begin(); iter != windows.end(); iter++) {
1098 if (delegate->ShouldStopIterating(*iter))
1099 return true;
1100 }
1101 windows.clear();
1102 }
1103
1104 XID root, parent, *children;
1105 unsigned int num_children;
1106 int status = XQueryTree(gfx::GetXDisplay(), window, &root, &parent, &children,
1107 &num_children);
1108 if (status == 0)
1109 return false;
1110
1111 for (int i = static_cast<int>(num_children) - 1; i >= 0; i--)
1112 windows.push_back(children[i]);
1113
1114 XFree(children);
1115
1116 // XQueryTree returns the children of |window| in bottom-to-top order, so
1117 // reverse-iterate the list to check the windows from top-to-bottom.
1118 for (iter = windows.begin(); iter != windows.end(); iter++) {
1119 if (IsWindowNamed(*iter) && delegate->ShouldStopIterating(*iter))
1120 return true;
1121 }
1122
1123 // If we're at this point, we didn't find the window we're looking for at the
1124 // current level, so we need to recurse to the next level. We use a second
1125 // loop because the recursion and call to XQueryTree are expensive and is only
1126 // needed for a small number of cases.
1127 if (++depth <= max_depth) {
1128 for (iter = windows.begin(); iter != windows.end(); iter++) {
1129 if (EnumerateChildren(delegate, *iter, max_depth, depth))
1130 return true;
1131 }
1132 }
1133
1134 return false;
1135 }
1136
1137 bool EnumerateAllWindows(EnumerateWindowsDelegate* delegate, int max_depth) {
1138 XID root = GetX11RootWindow();
1139 return EnumerateChildren(delegate, root, max_depth, 0);
1140 }
1141
1142 void EnumerateTopLevelWindows(ui::EnumerateWindowsDelegate* delegate) {
1143 std::vector<XID> stack;
1144 if (!ui::GetXWindowStack(ui::GetX11RootWindow(), &stack)) {
1145 // Window Manager doesn't support _NET_CLIENT_LIST_STACKING, so fall back
1146 // to old school enumeration of all X windows. Some WMs parent 'top-level'
1147 // windows in unnamed actual top-level windows (ion WM), so extend the
1148 // search depth to all children of top-level windows.
1149 const int kMaxSearchDepth = 1;
1150 ui::EnumerateAllWindows(delegate, kMaxSearchDepth);
1151 return;
1152 }
1153 XMenuList::GetInstance()->InsertMenuWindowXIDs(&stack);
1154
1155 std::vector<XID>::iterator iter;
1156 for (iter = stack.begin(); iter != stack.end(); iter++) {
1157 if (delegate->ShouldStopIterating(*iter))
1158 return;
1159 }
1160 }
1161
1162 bool GetXWindowStack(Window window, std::vector<XID>* windows) { 1086 bool GetXWindowStack(Window window, std::vector<XID>* windows) {
1163 windows->clear(); 1087 windows->clear();
1164 1088
1165 Atom type; 1089 Atom type;
1166 int format; 1090 int format;
1167 unsigned long count; 1091 unsigned long count;
1168 unsigned char *data = NULL; 1092 unsigned char *data = NULL;
1169 if (GetProperty(window, 1093 if (GetProperty(window,
1170 "_NET_CLIENT_LIST_STACKING", 1094 "_NET_CLIENT_LIST_STACKING",
1171 ~0L, 1095 ~0L,
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 << "request_code " << static_cast<int>(error_event.request_code) << ", " 1366 << "request_code " << static_cast<int>(error_event.request_code) << ", "
1443 << "minor_code " << static_cast<int>(error_event.minor_code) 1367 << "minor_code " << static_cast<int>(error_event.minor_code)
1444 << " (" << request_str << ")"; 1368 << " (" << request_str << ")";
1445 } 1369 }
1446 1370
1447 // ---------------------------------------------------------------------------- 1371 // ----------------------------------------------------------------------------
1448 // End of x11_util_internal.h 1372 // End of x11_util_internal.h
1449 1373
1450 1374
1451 } // namespace ui 1375 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/x/x11_util.h ('k') | ui/gfx/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698