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

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

Issue 196213004: Allows menu host windows to be enumerated in DragTargetWindowFinder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Allows menu host windows to be enumerated in DragTargetWindowFinder (separated) Created 6 years, 8 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
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 17 matching lines...) Expand all
28 #include "base/memory/singleton.h" 28 #include "base/memory/singleton.h"
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 "third_party/skia/include/core/SkBitmap.h" 36 #include "third_party/skia/include/core/SkBitmap.h"
37 #include "third_party/skia/include/core/SkPostConfig.h" 37 #include "third_party/skia/include/core/SkPostConfig.h"
38 #include "ui/base/x/x11_menu_list.h"
38 #include "ui/base/x/x11_util_internal.h" 39 #include "ui/base/x/x11_util_internal.h"
39 #include "ui/events/event_utils.h" 40 #include "ui/events/event_utils.h"
40 #include "ui/events/keycodes/keyboard_code_conversion_x.h" 41 #include "ui/events/keycodes/keyboard_code_conversion_x.h"
41 #include "ui/events/x/device_data_manager.h" 42 #include "ui/events/x/device_data_manager.h"
42 #include "ui/events/x/touch_factory_x11.h" 43 #include "ui/events/x/touch_factory_x11.h"
43 #include "ui/gfx/canvas.h" 44 #include "ui/gfx/canvas.h"
44 #include "ui/gfx/image/image_skia.h" 45 #include "ui/gfx/image/image_skia.h"
45 #include "ui/gfx/image/image_skia_rep.h" 46 #include "ui/gfx/image/image_skia_rep.h"
46 #include "ui/gfx/point.h" 47 #include "ui/gfx/point.h"
47 #include "ui/gfx/point_conversions.h" 48 #include "ui/gfx/point_conversions.h"
(...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 1061
1061 XFree(prop.value); 1062 XFree(prop.value);
1062 return true; 1063 return true;
1063 } 1064 }
1064 1065
1065 bool EnumerateChildren(EnumerateWindowsDelegate* delegate, XID window, 1066 bool EnumerateChildren(EnumerateWindowsDelegate* delegate, XID window,
1066 const int max_depth, int depth) { 1067 const int max_depth, int depth) {
1067 if (depth > max_depth) 1068 if (depth > max_depth)
1068 return false; 1069 return false;
1069 1070
1071 std::vector<XID> windows;
1072 std::vector<XID>::iterator iter;
1073 if (depth == 0) {
1074 XMenuList::GetInstance()->InsertMenuWindowXIDs(&windows);
1075 // Enumerate the menus first.
1076 for (iter = windows.begin(); iter != windows.end(); iter++) {
1077 if (delegate->ShouldStopIterating(*iter))
1078 return true;
1079 }
1080 windows.clear();
1081 }
1082
1070 XID root, parent, *children; 1083 XID root, parent, *children;
1071 unsigned int num_children; 1084 unsigned int num_children;
1072 int status = XQueryTree(gfx::GetXDisplay(), window, &root, &parent, &children, 1085 int status = XQueryTree(gfx::GetXDisplay(), window, &root, &parent, &children,
1073 &num_children); 1086 &num_children);
1074 if (status == 0) 1087 if (status == 0)
1075 return false; 1088 return false;
1076 1089
1077 std::vector<XID> windows;
1078 for (int i = static_cast<int>(num_children) - 1; i >= 0; i--) 1090 for (int i = static_cast<int>(num_children) - 1; i >= 0; i--)
1079 windows.push_back(children[i]); 1091 windows.push_back(children[i]);
1080 1092
1081 XFree(children); 1093 XFree(children);
1082 1094
1083 // XQueryTree returns the children of |window| in bottom-to-top order, so 1095 // XQueryTree returns the children of |window| in bottom-to-top order, so
1084 // reverse-iterate the list to check the windows from top-to-bottom. 1096 // reverse-iterate the list to check the windows from top-to-bottom.
1085 std::vector<XID>::iterator iter;
1086 for (iter = windows.begin(); iter != windows.end(); iter++) { 1097 for (iter = windows.begin(); iter != windows.end(); iter++) {
1087 if (IsWindowNamed(*iter) && delegate->ShouldStopIterating(*iter)) 1098 if (IsWindowNamed(*iter) && delegate->ShouldStopIterating(*iter))
1088 return true; 1099 return true;
1089 } 1100 }
1090 1101
1091 // If we're at this point, we didn't find the window we're looking for at the 1102 // If we're at this point, we didn't find the window we're looking for at the
1092 // current level, so we need to recurse to the next level. We use a second 1103 // current level, so we need to recurse to the next level. We use a second
1093 // loop because the recursion and call to XQueryTree are expensive and is only 1104 // loop because the recursion and call to XQueryTree are expensive and is only
1094 // needed for a small number of cases. 1105 // needed for a small number of cases.
1095 if (++depth <= max_depth) { 1106 if (++depth <= max_depth) {
(...skipping 15 matching lines...) Expand all
1111 std::vector<XID> stack; 1122 std::vector<XID> stack;
1112 if (!ui::GetXWindowStack(ui::GetX11RootWindow(), &stack)) { 1123 if (!ui::GetXWindowStack(ui::GetX11RootWindow(), &stack)) {
1113 // Window Manager doesn't support _NET_CLIENT_LIST_STACKING, so fall back 1124 // Window Manager doesn't support _NET_CLIENT_LIST_STACKING, so fall back
1114 // to old school enumeration of all X windows. Some WMs parent 'top-level' 1125 // to old school enumeration of all X windows. Some WMs parent 'top-level'
1115 // windows in unnamed actual top-level windows (ion WM), so extend the 1126 // windows in unnamed actual top-level windows (ion WM), so extend the
1116 // search depth to all children of top-level windows. 1127 // search depth to all children of top-level windows.
1117 const int kMaxSearchDepth = 1; 1128 const int kMaxSearchDepth = 1;
1118 ui::EnumerateAllWindows(delegate, kMaxSearchDepth); 1129 ui::EnumerateAllWindows(delegate, kMaxSearchDepth);
1119 return; 1130 return;
1120 } 1131 }
1132 XMenuList::GetInstance()->InsertMenuWindowXIDs(&stack);
1121 1133
1122 std::vector<XID>::iterator iter; 1134 std::vector<XID>::iterator iter;
1123 for (iter = stack.begin(); iter != stack.end(); iter++) { 1135 for (iter = stack.begin(); iter != stack.end(); iter++) {
1124 if (delegate->ShouldStopIterating(*iter)) 1136 if (delegate->ShouldStopIterating(*iter))
1125 return; 1137 return;
1126 } 1138 }
1127 } 1139 }
1128 1140
1129 bool GetXWindowStack(Window window, std::vector<XID>* windows) { 1141 bool GetXWindowStack(Window window, std::vector<XID>* windows) {
1130 windows->clear(); 1142 windows->clear();
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
1589 << "request_code " << static_cast<int>(error_event.request_code) << ", " 1601 << "request_code " << static_cast<int>(error_event.request_code) << ", "
1590 << "minor_code " << static_cast<int>(error_event.minor_code) 1602 << "minor_code " << static_cast<int>(error_event.minor_code)
1591 << " (" << request_str << ")"; 1603 << " (" << request_str << ")";
1592 } 1604 }
1593 1605
1594 // ---------------------------------------------------------------------------- 1606 // ----------------------------------------------------------------------------
1595 // End of x11_util_internal.h 1607 // End of x11_util_internal.h
1596 1608
1597 1609
1598 } // namespace ui 1610 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698