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

Unified Diff: mojo/services/public/cpp/view_manager/lib/view.cc

Issue 732223002: Rebuild aura::Window's property system on top of mojo::View. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: The rest of the sky comments from the previous review. Created 6 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 side-by-side diff with in-line comments
Download patch
Index: mojo/services/public/cpp/view_manager/lib/view.cc
diff --git a/mojo/services/public/cpp/view_manager/lib/view.cc b/mojo/services/public/cpp/view_manager/lib/view.cc
index b371000ee798c25e46bd83667c09743b52a1dec6..90a36636192335c16a6808a67a55a36208d66c02 100644
--- a/mojo/services/public/cpp/view_manager/lib/view.cc
+++ b/mojo/services/public/cpp/view_manager/lib/view.cc
@@ -225,8 +225,8 @@ void View::SetVisible(bool value) {
FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewVisibilityChanged(this));
}
-void View::SetProperty(const std::string& name,
- const std::vector<uint8_t>* value) {
+void View::SetSharedProperty(const std::string& name,
+ const std::vector<uint8_t>* value) {
std::vector<uint8_t> old_value;
std::vector<uint8_t>* old_value_ptr = nullptr;
auto it = properties_.find(name);
@@ -248,8 +248,9 @@ void View::SetProperty(const std::string& name,
properties_.erase(it);
}
- FOR_EACH_OBSERVER(ViewObserver, observers_,
- OnViewPropertyChanged(this, name, old_value_ptr, value));
+ FOR_EACH_OBSERVER(
+ ViewObserver, observers_,
+ OnViewSharedPropertyChanged(this, name, old_value_ptr, value));
}
bool View::IsDrawn() const {
@@ -386,6 +387,14 @@ View::~View() {
// ViewManagerClientImpl.
if (manager_)
static_cast<ViewManagerClientImpl*>(manager_)->RemoveView(id_);
+
+ // Clear properties.
+ for (auto& pair : prop_map_) {
+ if (pair.second.deallocator)
+ (*pair.second.deallocator)(pair.second.value);
+ }
+ prop_map_.clear();
+
FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDestroyed(this));
}
@@ -400,6 +409,34 @@ View::View(ViewManager* manager)
drawn_(false) {
}
+int64 View::SetLocalPropertyInternal(const void* key,
+ const char* name,
+ PropertyDeallocator deallocator,
+ int64 value,
+ int64 default_value) {
+ int64 old = GetLocalPropertyInternal(key, default_value);
+ if (value == default_value) {
+ prop_map_.erase(key);
+ } else {
+ Value prop_value;
+ prop_value.name = name;
+ prop_value.value = value;
+ prop_value.deallocator = deallocator;
+ prop_map_[key] = prop_value;
+ }
+ FOR_EACH_OBSERVER(ViewObserver, observers_,
+ OnViewLocalPropertyChanged(this, key, old));
+ return old;
+}
+
+int64 View::GetLocalPropertyInternal(const void* key,
+ int64 default_value) const {
+ std::map<const void*, Value>::const_iterator iter = prop_map_.find(key);
+ if (iter == prop_map_.end())
+ return default_value;
+ return iter->second.value;
+}
+
void View::LocalDestroy() {
delete this;
}
« no previous file with comments | « mojo/services/public/cpp/view_manager/BUILD.gn ('k') | mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698