OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "components/webui_generator/view_model.h" | |
6 | |
7 #include "components/webui_generator/view.h" | |
8 | |
9 namespace webui_generator { | |
10 | |
11 ViewModel::ContextEditor::ContextEditor(ViewModel& view_model) | |
12 : view_model_(view_model), context_(view_model_.context()) { | |
13 } | |
14 | |
15 ViewModel::ContextEditor::~ContextEditor() { | |
16 view_model_.CommitContextChanges(); | |
17 } | |
18 | |
19 const ViewModel::ContextEditor& ViewModel::ContextEditor::SetBoolean( | |
20 const KeyType& key, | |
21 bool value) const { | |
22 context_.SetBoolean(key, value); | |
23 return *this; | |
24 } | |
25 | |
26 const ViewModel::ContextEditor& ViewModel::ContextEditor::SetInteger( | |
27 const KeyType& key, | |
28 int value) const { | |
29 context_.SetInteger(key, value); | |
30 return *this; | |
31 } | |
32 | |
33 const ViewModel::ContextEditor& ViewModel::ContextEditor::SetDouble( | |
34 const KeyType& key, | |
35 double value) const { | |
36 context_.SetDouble(key, value); | |
37 return *this; | |
38 } | |
39 | |
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; | |
45 } | |
46 | |
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; | |
52 } | |
53 | |
54 const ViewModel::ContextEditor& ViewModel::ContextEditor::SetStringList( | |
55 const KeyType& key, | |
56 const StringList& value) const { | |
57 context_.SetStringList(key, value); | |
58 return *this; | |
59 } | |
60 | |
61 const ViewModel::ContextEditor& ViewModel::ContextEditor::SetString16List( | |
62 const KeyType& key, | |
63 const String16List& value) const { | |
64 context_.SetString16List(key, value); | |
65 return *this; | |
66 } | |
67 | |
68 ViewModel::ViewModel() : view_(nullptr) { | |
69 } | |
70 | |
71 ViewModel::~ViewModel() { | |
72 } | |
73 | |
74 void ViewModel::SetView(View* view) { | |
75 view_ = view; | |
76 Initialize(); | |
77 } | |
78 | |
79 void ViewModel::OnChildrenReady() { | |
80 OnAfterChildrenReady(); | |
81 view_->OnViewModelReady(); | |
82 } | |
83 | |
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); | |
88 } | |
89 | |
90 void ViewModel::OnEvent(const std::string& event) { | |
91 } | |
92 | |
93 ViewModel::ContextEditor ViewModel::GetContextEditor() { | |
94 return ContextEditor(*this); | |
95 } | |
96 | |
97 void ViewModel::CommitContextChanges() { | |
98 if (!context().HasChanges()) | |
99 return; | |
100 | |
101 base::DictionaryValue diff; | |
102 context().GetChangesAndReset(&diff); | |
103 view_->OnContextChanged(diff); | |
104 } | |
105 | |
106 } // namespace webui_generator | |
OLD | NEW |