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

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

Issue 8387043: [Aura] Support always-on-top top level window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: adding AuraShellTestBase that creates/deletes Shell and fix win_aura crash 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
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 // 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 num_items, 107 num_items,
108 &remaining_bytes, 108 &remaining_bytes,
109 property); 109 property);
110 } 110 }
111 111
112 // A process wide singleton that manages the usage of X cursors. 112 // A process wide singleton that manages the usage of X cursors.
113 class XCursorCache { 113 class XCursorCache {
114 public: 114 public:
115 XCursorCache() {} 115 XCursorCache() {}
116 ~XCursorCache() { 116 ~XCursorCache() {
117 Display* display = base::MessagePumpForUI::GetDefaultXDisplay(); 117 Clear();
118 for (std::map<int, Cursor>::iterator it =
119 cache_.begin(); it != cache_.end(); ++it) {
120 XFreeCursor(display, it->second);
121 }
122 cache_.clear();
123 } 118 }
124 119
125 Cursor GetCursor(int cursor_shape) { 120 Cursor GetCursor(int cursor_shape) {
126 // Lookup cursor by attempting to insert a null value, which avoids 121 // Lookup cursor by attempting to insert a null value, which avoids
127 // a second pass through the map after a cache miss. 122 // a second pass through the map after a cache miss.
128 std::pair<std::map<int, Cursor>::iterator, bool> it = cache_.insert( 123 std::pair<std::map<int, Cursor>::iterator, bool> it = cache_.insert(
129 std::make_pair(cursor_shape, 0)); 124 std::make_pair(cursor_shape, 0));
130 if (it.second) { 125 if (it.second) {
131 Display* display = base::MessagePumpForUI::GetDefaultXDisplay(); 126 Display* display = base::MessagePumpForUI::GetDefaultXDisplay();
132 it.first->second = XCreateFontCursor(display, cursor_shape); 127 it.first->second = XCreateFontCursor(display, cursor_shape);
133 } 128 }
134 return it.first->second; 129 return it.first->second;
135 } 130 }
136 131
132 void Clear() {
133 Display* display = base::MessagePumpForUI::GetDefaultXDisplay();
134 for (std::map<int, Cursor>::iterator it =
135 cache_.begin(); it != cache_.end(); ++it) {
136 XFreeCursor(display, it->second);
137 }
138 cache_.clear();
139 }
140
137 private: 141 private:
138 // Maps X11 font cursor shapes to Cursor IDs. 142 // Maps X11 font cursor shapes to Cursor IDs.
139 std::map<int, Cursor> cache_; 143 std::map<int, Cursor> cache_;
140 144
141 DISALLOW_COPY_AND_ASSIGN(XCursorCache); 145 DISALLOW_COPY_AND_ASSIGN(XCursorCache);
142 }; 146 };
143 147
144 } // namespace 148 } // namespace
145 149
146 bool XDisplayExists() { 150 bool XDisplayExists() {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 215
212 return render_supported; 216 return render_supported;
213 } 217 }
214 218
215 int GetDefaultScreen(Display* display) { 219 int GetDefaultScreen(Display* display) {
216 return XDefaultScreen(display); 220 return XDefaultScreen(display);
217 } 221 }
218 222
219 Cursor GetXCursor(int cursor_shape) { 223 Cursor GetXCursor(int cursor_shape) {
220 CR_DEFINE_STATIC_LOCAL(XCursorCache, cache, ()); 224 CR_DEFINE_STATIC_LOCAL(XCursorCache, cache, ());
225
226 if (cursor_shape == kCursorClearXCursorCache) {
227 cache.Clear();
228 return 0;
229 }
230
221 return cache.GetCursor(cursor_shape); 231 return cache.GetCursor(cursor_shape);
222 } 232 }
223 233
224 XID GetX11RootWindow() { 234 XID GetX11RootWindow() {
225 return DefaultRootWindow(GetXDisplay()); 235 return DefaultRootWindow(GetXDisplay());
226 } 236 }
227 237
228 bool GetCurrentDesktop(int* desktop) { 238 bool GetCurrentDesktop(int* desktop) {
229 return GetIntProperty(GetX11RootWindow(), "_NET_CURRENT_DESKTOP", desktop); 239 return GetIntProperty(GetX11RootWindow(), "_NET_CURRENT_DESKTOP", desktop);
230 } 240 }
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 << "request_code " << static_cast<int>(error_event.request_code) << ", " 932 << "request_code " << static_cast<int>(error_event.request_code) << ", "
923 << "minor_code " << static_cast<int>(error_event.minor_code) 933 << "minor_code " << static_cast<int>(error_event.minor_code)
924 << " (" << request_str << ")"; 934 << " (" << request_str << ")";
925 } 935 }
926 936
927 // ---------------------------------------------------------------------------- 937 // ----------------------------------------------------------------------------
928 // End of x11_util_internal.h 938 // End of x11_util_internal.h
929 939
930 940
931 } // namespace ui 941 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698