[MacViews] Implement size constraints for app windows.
[chromium-blink-merge.git] / components / webui_generator / view_model.cc
blobd81ce98752807e6361fcf95b7f7032f49b6ddd28
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/webui_generator/view_model.h"
7 #include "components/webui_generator/view.h"
9 namespace webui_generator {
11 ViewModel::ContextEditor::ContextEditor(ViewModel& view_model)
12 : view_model_(view_model), context_(view_model_.context()) {
15 ViewModel::ContextEditor::~ContextEditor() {
16 view_model_.CommitContextChanges();
19 const ViewModel::ContextEditor& ViewModel::ContextEditor::SetBoolean(
20 const KeyType& key,
21 bool value) const {
22 context_.SetBoolean(key, value);
23 return *this;
26 const ViewModel::ContextEditor& ViewModel::ContextEditor::SetInteger(
27 const KeyType& key,
28 int value) const {
29 context_.SetInteger(key, value);
30 return *this;
33 const ViewModel::ContextEditor& ViewModel::ContextEditor::SetDouble(
34 const KeyType& key,
35 double value) const {
36 context_.SetDouble(key, value);
37 return *this;
40 const ViewModel::ContextEditor& ViewModel::ContextEditor::SetString(
41 const KeyType& key,
42 const std::string& value) const {
43 context_.SetString(key, value);
44 return *this;
47 const ViewModel::ContextEditor& ViewModel::ContextEditor::SetString(
48 const KeyType& key,
49 const base::string16& value) const {
50 context_.SetString(key, value);
51 return *this;
54 const ViewModel::ContextEditor& ViewModel::ContextEditor::SetStringList(
55 const KeyType& key,
56 const StringList& value) const {
57 context_.SetStringList(key, value);
58 return *this;
61 const ViewModel::ContextEditor& ViewModel::ContextEditor::SetString16List(
62 const KeyType& key,
63 const String16List& value) const {
64 context_.SetString16List(key, value);
65 return *this;
68 ViewModel::ViewModel() : view_(nullptr) {
71 ViewModel::~ViewModel() {
74 void ViewModel::SetView(View* view) {
75 view_ = view;
76 Initialize();
79 void ViewModel::OnChildrenReady() {
80 OnAfterChildrenReady();
81 view_->OnViewModelReady();
84 void ViewModel::UpdateContext(const base::DictionaryValue& diff) {
85 std::vector<std::string> changed_keys;
86 context_.ApplyChanges(diff, &changed_keys);
87 OnContextChanged(changed_keys);
90 void ViewModel::OnEvent(const std::string& event) {
93 ViewModel::ContextEditor ViewModel::GetContextEditor() {
94 return ContextEditor(*this);
97 void ViewModel::CommitContextChanges() {
98 if (!context().HasChanges())
99 return;
101 base::DictionaryValue diff;
102 context().GetChangesAndReset(&diff);
103 view_->OnContextChanged(diff);
106 } // namespace webui_generator