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

Side by Side Diff: ui/base/view_prop.cc

Issue 10241005: Make win_aura work without ash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 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
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 "ui/base/view_prop.h" 5 #include "ui/base/view_prop.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 namespace ui { 9 namespace ui {
10 10
11 // Maints the actual view, key and data. 11 // Maints the actual view, key and data.
12 class ViewProp::Data : public base::RefCounted<ViewProp::Data> { 12 class ViewProp::Data : public base::RefCounted<ViewProp::Data> {
13 public: 13 public:
14 // Returns the Data* for the view/key pair. If |create| is false and |Get| 14 // Returns the Data* for the view/key pair. If |create| is false and |Get|
15 // has not been invoked for the view/key pair, NULL is returned. 15 // has not been invoked for the view/key pair, NULL is returned.
16 static void Get(gfx::NativeView view, 16 static void Get(gfx::AcceleratedWidget view,
17 const char* key, 17 const char* key,
18 bool create, 18 bool create,
19 scoped_refptr<Data>* data) { 19 scoped_refptr<Data>* data) {
20 if (!data_set_) 20 if (!data_set_)
21 data_set_ = new DataSet; 21 data_set_ = new DataSet;
22 scoped_refptr<Data> new_data(new Data(view, key)); 22 scoped_refptr<Data> new_data(new Data(view, key));
23 DataSet::const_iterator i = data_set_->find(new_data.get()); 23 DataSet::const_iterator i = data_set_->find(new_data.get());
24 if (i != data_set_->end()) { 24 if (i != data_set_->end()) {
25 *data = *i; 25 *data = *i;
26 return; 26 return;
(...skipping 17 matching lines...) Expand all
44 class DataComparator { 44 class DataComparator {
45 public: 45 public:
46 bool operator()(const Data* d1, const Data* d2) const { 46 bool operator()(const Data* d1, const Data* d2) const {
47 return (d1->view_ == d2->view_) ? (d1->key_ < d2->key_) : 47 return (d1->view_ == d2->view_) ? (d1->key_ < d2->key_) :
48 (d1->view_ < d2->view_); 48 (d1->view_ < d2->view_);
49 } 49 }
50 }; 50 };
51 51
52 typedef std::set<Data*, DataComparator> DataSet; 52 typedef std::set<Data*, DataComparator> DataSet;
53 53
54 Data(gfx::NativeView view, const char* key) 54 Data(gfx::AcceleratedWidget view, const char* key)
55 : view_(view), 55 : view_(view),
56 key_(key), 56 key_(key),
57 data_(NULL) {} 57 data_(NULL) {}
58 58
59 ~Data() { 59 ~Data() {
60 DataSet::iterator i = data_set_->find(this); 60 DataSet::iterator i = data_set_->find(this);
61 // Also check for equality using == as |Get| creates dummy values in order 61 // Also check for equality using == as |Get| creates dummy values in order
62 // to look up a value. 62 // to look up a value.
63 if (i != data_set_->end() && *i == this) 63 if (i != data_set_->end() && *i == this)
64 data_set_->erase(i); 64 data_set_->erase(i);
65 } 65 }
66 66
67 // The existing set of Data is stored here. ~Data removes from the set. 67 // The existing set of Data is stored here. ~Data removes from the set.
68 static DataSet* data_set_; 68 static DataSet* data_set_;
69 69
70 const gfx::NativeView view_; 70 const gfx::AcceleratedWidget view_;
71 const char* key_; 71 const char* key_;
72 void* data_; 72 void* data_;
73 73
74 DISALLOW_COPY_AND_ASSIGN(Data); 74 DISALLOW_COPY_AND_ASSIGN(Data);
75 }; 75 };
76 76
77 // static 77 // static
78 ViewProp::Data::DataSet* ViewProp::Data::data_set_ = NULL; 78 ViewProp::Data::DataSet* ViewProp::Data::data_set_ = NULL;
79 79
80 ViewProp::ViewProp(gfx::NativeView view, const char* key, void* data) { 80 ViewProp::ViewProp(gfx::AcceleratedWidget view, const char* key, void* data) {
81 Data::Get(view, key, true, &data_); 81 Data::Get(view, key, true, &data_);
82 data_->set_data(data); 82 data_->set_data(data);
83 } 83 }
84 84
85 ViewProp::~ViewProp() { 85 ViewProp::~ViewProp() {
86 // This is done to provide similar semantics to SetProp. In particular it's 86 // This is done to provide similar semantics to SetProp. In particular it's
87 // assumed that ~ViewProp should behave as though RemoveProp was invoked. 87 // assumed that ~ViewProp should behave as though RemoveProp was invoked.
88 data_->set_data(NULL); 88 data_->set_data(NULL);
89 } 89 }
90 90
91 // static 91 // static
92 void* ViewProp::GetValue(gfx::NativeView view, const char* key) { 92 void* ViewProp::GetValue(gfx::AcceleratedWidget view, const char* key) {
93 scoped_refptr<Data> data; 93 scoped_refptr<Data> data;
94 Data::Get(view, key, false, &data); 94 Data::Get(view, key, false, &data);
95 return data.get() ? data->data() : NULL; 95 return data.get() ? data->data() : NULL;
96 } 96 }
97 97
98 // static 98 // static
99 const char* ViewProp::Key() const { 99 const char* ViewProp::Key() const {
100 return data_->key(); 100 return data_->key();
101 } 101 }
102 102
103 } // namespace ui 103 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698