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

Unified Diff: mojo/examples/window_manager/window_manager.cc

Issue 460863002: Rename Node to View in the View Manager mojom & client lib. Service TBD. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/examples/window_manager/debug_panel.cc ('k') | mojo/examples/wm_flow/app/app.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/examples/window_manager/window_manager.cc
diff --git a/mojo/examples/window_manager/window_manager.cc b/mojo/examples/window_manager/window_manager.cc
index 525e032e5fe8c8abb2a28e9c9efa3176d72bb211..e1026a37579a7e5be657b9e1952c756f2660729a 100644
--- a/mojo/examples/window_manager/window_manager.cc
+++ b/mojo/examples/window_manager/window_manager.cc
@@ -13,11 +13,11 @@
#include "mojo/public/cpp/application/interface_factory_impl.h"
#include "mojo/services/public/cpp/geometry/geometry_type_converters.h"
#include "mojo/services/public/cpp/input_events/input_events_type_converters.h"
-#include "mojo/services/public/cpp/view_manager/node.h"
-#include "mojo/services/public/cpp/view_manager/node_observer.h"
+#include "mojo/services/public/cpp/view_manager/view.h"
#include "mojo/services/public/cpp/view_manager/view_manager.h"
#include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h"
#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
+#include "mojo/services/public/cpp/view_manager/view_observer.h"
#include "mojo/services/public/cpp/view_manager/window_manager_delegate.h"
#include "mojo/services/public/interfaces/input_events/input_events.mojom.h"
#include "mojo/services/public/interfaces/launcher/launcher.mojom.h"
@@ -52,7 +52,7 @@ class WindowManagerConnection : public InterfaceImpl<IWindowManager> {
private:
// Overridden from IWindowManager:
- virtual void CloseWindow(Id node_id) OVERRIDE;
+ virtual void CloseWindow(Id view_id) OVERRIDE;
virtual void ShowKeyboard(Id view_id, RectPtr bounds) OVERRIDE;
virtual void HideKeyboard(Id view_id) OVERRIDE;
@@ -69,10 +69,10 @@ class NavigatorHostImpl : public InterfaceImpl<NavigatorHost> {
}
private:
- virtual void DidNavigateLocally(uint32 source_node_id,
+ virtual void DidNavigateLocally(uint32 source_view_id,
const mojo::String& url) OVERRIDE;
virtual void RequestNavigate(
- uint32 source_node_id,
+ uint32 source_view_id,
Target target,
NavigationDetailsPtr nav_details) OVERRIDE;
WindowManager* window_manager_;
@@ -81,26 +81,26 @@ class NavigatorHostImpl : public InterfaceImpl<NavigatorHost> {
};
class KeyboardManager : public KeyboardClient,
- public NodeObserver {
+ public ViewObserver {
public:
- KeyboardManager() : view_manager_(NULL), node_(NULL) {
+ KeyboardManager() : view_manager_(NULL), view_(NULL) {
}
virtual ~KeyboardManager() {
- if (node_)
- node_->parent()->RemoveObserver(this);
+ if (view_)
+ view_->parent()->RemoveObserver(this);
}
- Node* node() { return node_; }
+ View* view() { return view_; }
void Init(ApplicationImpl* application,
ViewManager* view_manager,
- Node* parent,
+ View* parent,
const gfx::Rect& bounds) {
view_manager_ = view_manager;
- node_ = Node::Create(view_manager);
- node_->SetBounds(bounds);
- parent->AddChild(node_);
- node_->Embed("mojo:mojo_keyboard");
+ view_ = View::Create(view_manager);
+ view_->SetBounds(bounds);
+ parent->AddChild(view_);
+ view_->Embed("mojo:mojo_keyboard");
application->ConnectToService("mojo:mojo_keyboard", &keyboard_service_);
keyboard_service_.set_client(this);
parent->AddObserver(this);
@@ -108,21 +108,21 @@ class KeyboardManager : public KeyboardClient,
void Show(Id view_id, const gfx::Rect& bounds) {
keyboard_service_->SetTarget(view_id);
- node_->SetVisible(true);
+ view_->SetVisible(true);
}
void Hide(Id view_id) {
keyboard_service_->SetTarget(0);
- node_->SetVisible(false);
+ view_->SetVisible(false);
}
private:
// KeyboardClient:
- virtual void OnKeyboardEvent(Id node_id,
+ virtual void OnKeyboardEvent(Id view_id,
int32_t code,
int32_t flags) OVERRIDE {
- Node* node = view_manager_->GetNodeById(node_id);
- if (!node)
+ View* view = view_manager_->GetViewById(view_id);
+ if (!view)
return;
#if defined(OS_WIN)
const bool is_char = code != ui::VKEY_BACK && code != ui::VKEY_RETURN;
@@ -131,117 +131,117 @@ class KeyboardManager : public KeyboardClient,
#endif
if (is_char) {
view_manager_->DispatchEvent(
- node,
+ view,
Event::From(ui::KeyEvent(ui::ET_KEY_PRESSED,
static_cast<ui::KeyboardCode>(code),
flags)));
} else {
view_manager_->DispatchEvent(
- node,
+ view,
Event::From(ui::KeyEvent(static_cast<base::char16>(code),
static_cast<ui::KeyboardCode>(code),
flags)));
}
view_manager_->DispatchEvent(
- node,
+ view,
Event::From(ui::KeyEvent(ui::ET_KEY_RELEASED,
static_cast<ui::KeyboardCode>(code),
flags)));
}
- // Overridden from NodeObserver:
- virtual void OnNodeBoundsChanged(Node* parent,
+ // Overridden from ViewObserver:
+ virtual void OnViewBoundsChanged(View* parent,
const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) OVERRIDE {
- gfx::Rect keyboard_bounds(node_->bounds());
+ gfx::Rect keyboard_bounds(view_->bounds());
keyboard_bounds.set_y(new_bounds.bottom() - keyboard_bounds.height());
keyboard_bounds.set_width(keyboard_bounds.width() +
new_bounds.width() - old_bounds.width());
- node_->SetBounds(keyboard_bounds);
+ view_->SetBounds(keyboard_bounds);
}
- virtual void OnNodeDestroyed(Node* parent) OVERRIDE {
- DCHECK_EQ(parent, node_->parent());
+ virtual void OnViewDestroyed(View* parent) OVERRIDE {
+ DCHECK_EQ(parent, view_->parent());
parent->RemoveObserver(this);
- node_ = NULL;
+ view_ = NULL;
}
KeyboardServicePtr keyboard_service_;
ViewManager* view_manager_;
- // Node the keyboard is attached to.
- Node* node_;
+ // View the keyboard is attached to.
+ View* view_;
DISALLOW_COPY_AND_ASSIGN(KeyboardManager);
};
-class RootLayoutManager : public NodeObserver {
+class RootLayoutManager : public ViewObserver {
public:
RootLayoutManager(ViewManager* view_manager,
- Node* root,
- Id content_node_id,
- Id launcher_ui_node_id,
- Id control_panel_node_id)
+ View* root,
+ Id content_view_id,
+ Id launcher_ui_view_id,
+ Id control_panel_view_id)
: root_(root),
view_manager_(view_manager),
- content_node_id_(content_node_id),
- launcher_ui_node_id_(launcher_ui_node_id),
- control_panel_node_id_(control_panel_node_id) {}
+ content_view_id_(content_view_id),
+ launcher_ui_view_id_(launcher_ui_view_id),
+ control_panel_view_id_(control_panel_view_id) {}
virtual ~RootLayoutManager() {
if (root_)
root_->RemoveObserver(this);
}
private:
- // Overridden from NodeObserver:
- virtual void OnNodeBoundsChanged(Node* node,
+ // Overridden from ViewObserver:
+ virtual void OnViewBoundsChanged(View* view,
const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) OVERRIDE {
- DCHECK_EQ(node, root_);
+ DCHECK_EQ(view, root_);
- Node* content_node = view_manager_->GetNodeById(content_node_id_);
- content_node->SetBounds(new_bounds);
+ View* content_view = view_manager_->GetViewById(content_view_id_);
+ content_view->SetBounds(new_bounds);
// Force the view's bitmap to be recreated
- content_node->SetColor(SK_ColorBLUE);
+ content_view->SetColor(SK_ColorBLUE);
int delta_width = new_bounds.width() - old_bounds.width();
int delta_height = new_bounds.height() - old_bounds.height();
- Node* launcher_ui_node =
- view_manager_->GetNodeById(launcher_ui_node_id_);
- gfx::Rect launcher_ui_bounds(launcher_ui_node->bounds());
+ View* launcher_ui_view =
+ view_manager_->GetViewById(launcher_ui_view_id_);
+ gfx::Rect launcher_ui_bounds(launcher_ui_view->bounds());
launcher_ui_bounds.set_width(launcher_ui_bounds.width() + delta_width);
- launcher_ui_node->SetBounds(launcher_ui_bounds);
+ launcher_ui_view->SetBounds(launcher_ui_bounds);
- Node* control_panel_node =
- view_manager_->GetNodeById(control_panel_node_id_);
- gfx::Rect control_panel_bounds(control_panel_node->bounds());
+ View* control_panel_view =
+ view_manager_->GetViewById(control_panel_view_id_);
+ gfx::Rect control_panel_bounds(control_panel_view->bounds());
control_panel_bounds.set_x(control_panel_bounds.x() + delta_width);
- control_panel_node->SetBounds(control_panel_bounds);
-
- const Node::Children& content_nodes = content_node->children();
- Node::Children::const_iterator iter = content_nodes.begin();
- for(; iter != content_nodes.end(); ++iter) {
- Node* node = *iter;
- if (node->id() == control_panel_node->id() ||
- node->id() == launcher_ui_node->id())
+ control_panel_view->SetBounds(control_panel_bounds);
+
+ const View::Children& content_views = content_view->children();
+ View::Children::const_iterator iter = content_views.begin();
+ for(; iter != content_views.end(); ++iter) {
+ View* view = *iter;
+ if (view->id() == control_panel_view->id() ||
+ view->id() == launcher_ui_view->id())
continue;
- gfx::Rect node_bounds(node->bounds());
- node_bounds.set_width(node_bounds.width() + delta_width);
- node_bounds.set_height(node_bounds.height() + delta_height);
- node->SetBounds(node_bounds);
+ gfx::Rect view_bounds(view->bounds());
+ view_bounds.set_width(view_bounds.width() + delta_width);
+ view_bounds.set_height(view_bounds.height() + delta_height);
+ view->SetBounds(view_bounds);
}
}
- virtual void OnNodeDestroyed(Node* node) OVERRIDE {
- DCHECK_EQ(node, root_);
+ virtual void OnViewDestroyed(View* view) OVERRIDE {
+ DCHECK_EQ(view, root_);
root_->RemoveObserver(this);
root_ = NULL;
}
- Node* root_;
+ View* root_;
ViewManager* view_manager_;
- const Id content_node_id_;
- const Id launcher_ui_node_id_;
- const Id control_panel_node_id_;
+ const Id content_view_id_;
+ const Id launcher_ui_view_id_;
+ const Id control_panel_view_id_;
DISALLOW_COPY_AND_ASSIGN(RootLayoutManager);
};
@@ -262,14 +262,14 @@ class WindowManager
virtual ~WindowManager() {}
- void CloseWindow(Id node_id) {
- Node* node = view_manager_->GetNodeById(node_id);
- DCHECK(node);
- std::vector<Node*>::iterator iter =
- std::find(windows_.begin(), windows_.end(), node);
+ void CloseWindow(Id view_id) {
+ View* view = view_manager_->GetViewById(view_id);
+ DCHECK(view);
+ std::vector<View*>::iterator iter =
+ std::find(windows_.begin(), windows_.end(), view);
DCHECK(iter != windows_.end());
windows_.erase(iter);
- node->Destroy();
+ view->Destroy();
}
void ShowKeyboard(Id view_id, const gfx::Rect& bounds) {
@@ -279,7 +279,7 @@ class WindowManager
// TODO: honor |bounds|.
if (!keyboard_manager_) {
keyboard_manager_.reset(new KeyboardManager);
- Node* parent = view_manager_->GetRoots().back();
+ View* parent = view_manager_->GetRoots().back();
int ideal_height = 200;
// TODO(sky): 10 is a bit of a hack here. There is a bug that causes
// white strips to appear when 0 is used. Figure this out!
@@ -297,8 +297,8 @@ class WindowManager
keyboard_manager_->Hide(view_id);
}
- void DidNavigateLocally(uint32 source_node_id, const mojo::String& url) {
- LOG(ERROR) << "DidNavigateLocally: source_node_id: " << source_node_id
+ void DidNavigateLocally(uint32 source_view_id, const mojo::String& url) {
+ LOG(ERROR) << "DidNavigateLocally: source_view_id: " << source_view_id
<< " url: " << url.To<std::string>();
}
@@ -309,13 +309,13 @@ class WindowManager
}
virtual void RequestNavigate(
- uint32 source_node_id,
+ uint32 source_view_id,
Target target,
NavigationDetailsPtr nav_details) OVERRIDE {
launcher_->Launch(nav_details.Pass(),
base::Bind(&WindowManager::OnLaunch,
base::Unretained(this),
- source_node_id,
+ source_view_id,
target));
}
@@ -337,26 +337,26 @@ class WindowManager
// Overridden from ViewManagerDelegate:
virtual void OnEmbed(ViewManager* view_manager,
- Node* root,
+ View* root,
ServiceProviderImpl* exported_services,
scoped_ptr<ServiceProvider> imported_services) OVERRIDE {
DCHECK(!view_manager_);
view_manager_ = view_manager;
view_manager_->SetWindowManagerDelegate(this);
- Node* node = Node::Create(view_manager_);
- root->AddChild(node);
- node->SetBounds(gfx::Rect(root->bounds().size()));
- content_node_id_ = node->id();
+ View* view = View::Create(view_manager_);
+ root->AddChild(view);
+ view->SetBounds(gfx::Rect(root->bounds().size()));
+ content_view_id_ = view->id();
root->SetColor(SK_ColorBLUE);
Id launcher_ui_id = CreateLauncherUI();
- Id control_panel_id = CreateControlPanel(node);
+ Id control_panel_id = CreateControlPanel(view);
root_layout_manager_.reset(
new RootLayoutManager(view_manager, root,
- content_node_id_,
+ content_view_id_,
launcher_ui_id,
control_panel_id));
root->AddObserver(root_layout_manager_.get());
@@ -375,7 +375,7 @@ class WindowManager
NavigationDetailsPtr().Pass(),
ResponseDetailsPtr().Pass());
}
- virtual void DispatchEvent(Node* target, EventPtr event) OVERRIDE {
+ virtual void DispatchEvent(View* target, EventPtr event) OVERRIDE {
// TODO(beng): More sophisticated focus handling than this is required!
if (event->action == EVENT_TYPE_MOUSE_PRESSED &&
!IsDescendantOfKeyboard(target)) {
@@ -385,7 +385,7 @@ class WindowManager
}
void OnLaunch(
- uint32 source_node_id,
+ uint32 source_view_id,
Target requested_target,
const mojo::String& handler_url,
const mojo::String& view_url,
@@ -407,19 +407,19 @@ class WindowManager
}
}
- Node* dest_node = NULL;
+ View* dest_view = NULL;
if (target == TARGET_SOURCE_NODE) {
- Node* source_node = view_manager_->GetNodeById(source_node_id);
+ View* source_view = view_manager_->GetViewById(source_view_id);
bool app_initiated = std::find(windows_.begin(), windows_.end(),
- source_node) != windows_.end();
+ source_view) != windows_.end();
if (app_initiated)
- dest_node = source_node;
+ dest_view = source_view;
else if (!windows_.empty())
- dest_node = windows_.back();
+ dest_view = windows_.back();
}
- if (dest_node)
- Embed(dest_node, handler_url, nav_details.Pass(), response.Pass());
+ if (dest_view)
+ Embed(dest_view, handler_url, nav_details.Pass(), response.Pass());
else
CreateWindow(handler_url, nav_details.Pass(), response.Pass());
}
@@ -428,11 +428,11 @@ class WindowManager
Id CreateLauncherUI() {
NavigationDetailsPtr nav_details;
ResponseDetailsPtr response;
- Node* node = view_manager_->GetNodeById(content_node_id_);
- gfx::Rect bounds = node->bounds();
+ View* view = view_manager_->GetViewById(content_view_id_);
+ gfx::Rect bounds = view->bounds();
bounds.Inset(kBorderInset, kBorderInset);
bounds.set_height(kTextfieldHeight);
- launcher_ui_ = CreateChild(content_node_id_, "mojo:mojo_browser", bounds,
+ launcher_ui_ = CreateChild(content_view_id_, "mojo:mojo_browser", bounds,
nav_details.Pass(), response.Pass());
return launcher_ui_->id();
}
@@ -440,55 +440,55 @@ class WindowManager
void CreateWindow(const std::string& handler_url,
NavigationDetailsPtr nav_details,
ResponseDetailsPtr response) {
- Node* node = view_manager_->GetNodeById(content_node_id_);
+ View* view = view_manager_->GetViewById(content_view_id_);
gfx::Rect bounds(kBorderInset,
2 * kBorderInset + kTextfieldHeight,
- node->bounds().width() - 3 * kBorderInset -
+ view->bounds().width() - 3 * kBorderInset -
kControlPanelWidth,
- node->bounds().height() -
+ view->bounds().height() -
(3 * kBorderInset + kTextfieldHeight));
if (!windows_.empty()) {
gfx::Point position = windows_.back()->bounds().origin();
position.Offset(35, 35);
bounds.set_origin(position);
}
- windows_.push_back(CreateChild(content_node_id_, handler_url, bounds,
+ windows_.push_back(CreateChild(content_view_id_, handler_url, bounds,
nav_details.Pass(), response.Pass()));
}
- Node* CreateChild(Id parent_id,
+ View* CreateChild(Id parent_id,
const std::string& url,
const gfx::Rect& bounds,
NavigationDetailsPtr nav_details,
ResponseDetailsPtr response) {
- Node* node = view_manager_->GetNodeById(parent_id);
- Node* embedded = Node::Create(view_manager_);
- node->AddChild(embedded);
+ View* view = view_manager_->GetViewById(parent_id);
+ View* embedded = View::Create(view_manager_);
+ view->AddChild(embedded);
embedded->SetBounds(bounds);
Embed(embedded, url, nav_details.Pass(), response.Pass());
embedded->SetFocus();
return embedded;
}
- void Embed(Node* node, const std::string& app_url,
+ void Embed(View* view, const std::string& app_url,
NavigationDetailsPtr nav_details,
ResponseDetailsPtr response) {
- node->Embed(app_url);
+ view->Embed(app_url);
if (nav_details) {
NavigatorPtr navigator;
app_->ConnectToService(app_url, &navigator);
- navigator->Navigate(node->id(), nav_details.Pass(), response.Pass());
+ navigator->Navigate(view->id(), nav_details.Pass(), response.Pass());
}
}
- bool IsDescendantOfKeyboard(Node* target) {
+ bool IsDescendantOfKeyboard(View* target) {
return keyboard_manager_.get() &&
- keyboard_manager_->node()->Contains(target);
+ keyboard_manager_->view()->Contains(target);
}
- Id CreateControlPanel(Node* root) {
- Node* node = Node::Create(view_manager_);
- root->AddChild(node);
+ Id CreateControlPanel(View* root) {
+ View* view = View::Create(view_manager_);
+ root->AddChild(view);
gfx::Rect bounds(root->bounds().width() - kControlPanelWidth -
kBorderInset,
@@ -496,10 +496,10 @@ class WindowManager
kControlPanelWidth,
root->bounds().height() - kBorderInset * 3 -
kTextfieldHeight);
- node->SetBounds(bounds);
+ view->SetBounds(bounds);
- debug_panel_ = new DebugPanel(this, node);
- return node->id();
+ debug_panel_ = new DebugPanel(this, view);
+ return view->id();
}
InterfaceFactoryImplWithContext<WindowManagerConnection, WindowManager>
@@ -510,14 +510,14 @@ class WindowManager
scoped_ptr<ViewsInit> views_init_;
DebugPanel* debug_panel_;
LauncherPtr launcher_;
- Node* launcher_ui_;
- std::vector<Node*> windows_;
+ View* launcher_ui_;
+ std::vector<View*> windows_;
ViewManager* view_manager_;
ViewManagerClientFactory view_manager_client_factory_;
scoped_ptr<RootLayoutManager> root_layout_manager_;
- // Id of the node most content is added to. The keyboard is NOT added here.
- Id content_node_id_;
+ // Id of the view most content is added to. The keyboard is NOT added here.
+ Id content_view_id_;
scoped_ptr<KeyboardManager> keyboard_manager_;
ApplicationImpl* app_;
@@ -525,28 +525,28 @@ class WindowManager
DISALLOW_COPY_AND_ASSIGN(WindowManager);
};
-void WindowManagerConnection::CloseWindow(Id node_id) {
- window_manager_->CloseWindow(node_id);
+void WindowManagerConnection::CloseWindow(Id view_id) {
+ window_manager_->CloseWindow(view_id);
}
void WindowManagerConnection::ShowKeyboard(Id view_id, RectPtr bounds) {
window_manager_->ShowKeyboard(view_id, bounds.To<gfx::Rect>());
}
-void WindowManagerConnection::HideKeyboard(Id node_id) {
- window_manager_->HideKeyboard(node_id);
+void WindowManagerConnection::HideKeyboard(Id view_id) {
+ window_manager_->HideKeyboard(view_id);
}
-void NavigatorHostImpl::DidNavigateLocally(uint32 source_node_id,
+void NavigatorHostImpl::DidNavigateLocally(uint32 source_view_id,
const mojo::String& url) {
- window_manager_->DidNavigateLocally(source_node_id, url);
+ window_manager_->DidNavigateLocally(source_view_id, url);
}
void NavigatorHostImpl::RequestNavigate(
- uint32 source_node_id,
+ uint32 source_view_id,
Target target,
NavigationDetailsPtr nav_details) {
- window_manager_->RequestNavigate(source_node_id, target, nav_details.Pass());
+ window_manager_->RequestNavigate(source_view_id, target, nav_details.Pass());
}
} // namespace examples
« no previous file with comments | « mojo/examples/window_manager/debug_panel.cc ('k') | mojo/examples/wm_flow/app/app.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698