OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "mojo/examples/window_manager/window_manager.mojom.h" | 8 #include "mojo/examples/window_manager/window_manager.mojom.h" |
9 #include "mojo/public/cpp/application/application.h" | 9 #include "mojo/public/cpp/application/application.h" |
10 #include "mojo/services/navigation/navigation.mojom.h" | 10 #include "mojo/services/navigation/navigation.mojom.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 ViewManager::Create(this, this); | 80 ViewManager::Create(this, this); |
81 } | 81 } |
82 | 82 |
83 // Overridden from ViewObserver: | 83 // Overridden from ViewObserver: |
84 virtual void OnViewInputEvent(View* view, const EventPtr& event) OVERRIDE { | 84 virtual void OnViewInputEvent(View* view, const EventPtr& event) OVERRIDE { |
85 if (event->action == ui::ET_MOUSE_RELEASED) { | 85 if (event->action == ui::ET_MOUSE_RELEASED) { |
86 if (event->flags & ui::EF_LEFT_MOUSE_BUTTON) | 86 if (event->flags & ui::EF_LEFT_MOUSE_BUTTON) |
87 CreateWindow(kEmbeddedAppURL); | 87 CreateWindow(kEmbeddedAppURL); |
88 else if (event->flags & ui::EF_RIGHT_MOUSE_BUTTON) | 88 else if (event->flags & ui::EF_RIGHT_MOUSE_BUTTON) |
89 CreateWindow(kNestingAppURL); | 89 CreateWindow(kNestingAppURL); |
90 else if (event->flags & ui::EF_MIDDLE_MOUSE_BUTTON) | |
91 CreateWindow(kMojoBrowserURL); | |
92 } | 90 } |
93 } | 91 } |
94 | 92 |
95 // Overridden from ViewManagerDelegate: | 93 // Overridden from ViewManagerDelegate: |
96 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE { | 94 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE { |
97 DCHECK(!view_manager_); | 95 DCHECK(!view_manager_); |
98 view_manager_ = view_manager; | 96 view_manager_ = view_manager; |
99 | 97 |
100 Node* node = Node::Create(view_manager); | 98 Node* node = Node::Create(view_manager); |
101 view_manager->GetRoots().front()->AddChild(node); | 99 view_manager->GetRoots().front()->AddChild(node); |
102 node->SetBounds(gfx::Rect(800, 600)); | 100 node->SetBounds(gfx::Rect(800, 600)); |
103 parent_node_id_ = node->id(); | 101 parent_node_id_ = node->id(); |
104 | 102 |
105 View* view = View::Create(view_manager); | 103 View* view = View::Create(view_manager); |
106 node->SetActiveView(view); | 104 node->SetActiveView(view); |
107 view->SetColor(SK_ColorBLUE); | 105 view->SetColor(SK_ColorBLUE); |
108 view->AddObserver(this); | 106 view->AddObserver(this); |
| 107 |
| 108 CreateWindow(kMojoBrowserURL); |
109 } | 109 } |
110 | 110 |
111 void CreateWindow(const std::string& url) { | 111 void CreateWindow(const std::string& url) { |
112 Node* node = view_manager_->GetNodeById(parent_node_id_); | 112 Node* node = view_manager_->GetNodeById(parent_node_id_); |
113 | 113 |
114 gfx::Rect bounds(50, 50, 400, 400); | 114 gfx::Rect bounds(node->bounds().size()); |
| 115 bounds.Inset(25, 25); |
115 if (!node->children().empty()) { | 116 if (!node->children().empty()) { |
116 gfx::Point position = node->children().back()->bounds().origin(); | 117 gfx::Point position = node->children().back()->bounds().origin(); |
117 position.Offset(50, 50); | 118 position.Offset(25, 25); |
118 bounds.set_origin(position); | 119 bounds.set_origin(position); |
119 } | 120 } |
120 | 121 |
121 Node* embedded = Node::Create(view_manager_); | 122 Node* embedded = Node::Create(view_manager_); |
122 node->AddChild(embedded); | 123 node->AddChild(embedded); |
123 embedded->SetBounds(bounds); | 124 embedded->SetBounds(bounds); |
124 embedded->Embed(url); | 125 embedded->Embed(url); |
125 | 126 |
126 // TODO(aa): Is there a way to ask for an interface and test whether it | 127 // TODO(aa): Is there a way to ask for an interface and test whether it |
127 // succeeded? That would be nicer than hard-coding the URLs that are known | 128 // succeeded? That would be nicer than hard-coding the URLs that are known |
(...skipping 24 matching lines...) Expand all Loading... |
152 } | 153 } |
153 | 154 |
154 } // namespace examples | 155 } // namespace examples |
155 | 156 |
156 // static | 157 // static |
157 Application* Application::Create() { | 158 Application* Application::Create() { |
158 return new examples::WindowManager; | 159 return new examples::WindowManager; |
159 } | 160 } |
160 | 161 |
161 } // namespace mojo | 162 } // namespace mojo |
OLD | NEW |