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

Side by Side Diff: ui/gfx/gtk_util.cc

Issue 9804003: ui/gfx: Add a typedef of std::map to improve the readability of GdkCursorCache implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rm unused base/linux_util.h Created 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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) 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 #include "ui/gfx/gtk_util.h" 5 #include "ui/gfx/gtk_util.h"
6 6
7 #include <gdk/gdk.h> 7 #include <gdk/gdk.h>
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/linux_util.h"
14 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
15 #include "third_party/skia/include/core/SkBitmap.h" 14 #include "third_party/skia/include/core/SkBitmap.h"
16 #include "third_party/skia/include/core/SkUnPreMultiply.h" 15 #include "third_party/skia/include/core/SkUnPreMultiply.h"
17 #include "ui/gfx/rect.h" 16 #include "ui/gfx/rect.h"
18 17
19 namespace { 18 namespace {
20 19
21 // A process wide singleton that manages our usage of gdk 20 // A process wide singleton that manages our usage of gdk cursors.
22 // cursors. gdk_cursor_new() hits the disk in several places and GdkCursor 21 // gdk_cursor_new() hits the disk in several places and GdkCursor instances can
23 // instances can be reused throughout the process. 22 // be reused throughout the process.
24 class GdkCursorCache { 23 class GdkCursorCache {
25 public: 24 public:
26 GdkCursorCache() {} 25 GdkCursorCache() {}
27 ~GdkCursorCache() { 26 ~GdkCursorCache() {
28 for (std::map<GdkCursorType, GdkCursor*>::iterator it = 27 for (GdkCursorMap::iterator i(cursors_.begin()); i != cursors_.end(); ++i) {
29 cursor_cache_.begin(); it != cursor_cache_.end(); ++it) { 28 gdk_cursor_unref(i->second);
30 gdk_cursor_unref(it->second);
31 } 29 }
32 cursor_cache_.clear(); 30 cursors_.clear();
33 } 31 }
34 32
35 GdkCursor* GetCursorImpl(GdkCursorType type) { 33 GdkCursor* GetCursorImpl(GdkCursorType type) {
36 std::map<GdkCursorType, GdkCursor*>::iterator it = cursor_cache_.find(type); 34 GdkCursorMap::iterator it = cursors_.find(type);
37 GdkCursor* cursor = NULL; 35 GdkCursor* cursor = NULL;
38 if (it == cursor_cache_.end()) { 36 if (it == cursors_.end()) {
39 cursor = gdk_cursor_new(type); 37 cursor = gdk_cursor_new(type);
40 cursor_cache_.insert(std::make_pair(type, cursor)); 38 cursors_.insert(std::make_pair(type, cursor));
41 } else { 39 } else {
42 cursor = it->second; 40 cursor = it->second;
43 } 41 }
44 42
45 // It is not necessary to add a reference here. The callers can ref the 43 // It is not necessary to add a reference here. The callers can ref the
46 // cursor if they need it for something. 44 // cursor if they need it for something.
47 return cursor; 45 return cursor;
48 } 46 }
49 47
50 std::map<GdkCursorType, GdkCursor*> cursor_cache_; 48 private:
49 typedef std::map<GdkCursorType, GdkCursor*> GdkCursorMap;
50 GdkCursorMap cursors_;
51 51
52 DISALLOW_COPY_AND_ASSIGN(GdkCursorCache); 52 DISALLOW_COPY_AND_ASSIGN(GdkCursorCache);
53 }; 53 };
54 54
55 void FreePixels(guchar* pixels, gpointer data) { 55 void FreePixels(guchar* pixels, gpointer data) {
56 free(data); 56 free(data);
57 } 57 }
58 58
59 } // namespace 59 } // namespace
60 60
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 " GtkDialog::button-spacing = 6\n" 165 " GtkDialog::button-spacing = 6\n"
166 " GtkDialog::content-area-spacing = 18\n" 166 " GtkDialog::content-area-spacing = 18\n"
167 " GtkDialog::content-area-border = 0\n" 167 " GtkDialog::content-area-border = 0\n"
168 "}\n" 168 "}\n"
169 "widget \"about-dialog\" style : application \"about-dialog\"\n"; 169 "widget \"about-dialog\" style : application \"about-dialog\"\n";
170 170
171 gtk_rc_parse_string(kRCText); 171 gtk_rc_parse_string(kRCText);
172 } 172 }
173 173
174 } // namespace gfx 174 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698