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

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

Issue 799113004: Update mojo sdk to rev 59145288bae55b0fce4276b017df6a1117bcf00f (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add mojo's ply to checklicenses whitelist Created 6 years 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/view_manager/public/cpp/lib/view_manager_client_impl.cc
diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc b/mojo/services/view_manager/public/cpp/lib/view_manager_client_impl.cc
similarity index 89%
rename from mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc
rename to mojo/services/view_manager/public/cpp/lib/view_manager_client_impl.cc
index e70ec2bda312cb1a0fd95ce49870f8c182e0d473..fd618b87d3c77790f5f8c9bd93426a51f8f5df44 100644
--- a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc
+++ b/mojo/services/view_manager/public/cpp/lib/view_manager_client_impl.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h"
+#include "mojo/services/view_manager/public/cpp/lib/view_manager_client_impl.h"
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
@@ -12,10 +12,10 @@
#include "mojo/public/cpp/application/service_provider_impl.h"
#include "mojo/public/interfaces/application/service_provider.mojom.h"
#include "mojo/public/interfaces/application/shell.mojom.h"
-#include "mojo/services/public/cpp/view_manager/lib/view_private.h"
-#include "mojo/services/public/cpp/view_manager/util.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/view_manager/public/cpp/lib/view_private.h"
+#include "mojo/services/view_manager/public/cpp/util.h"
+#include "mojo/services/view_manager/public/cpp/view_manager_delegate.h"
+#include "mojo/services/view_manager/public/cpp/view_observer.h"
namespace mojo {
@@ -81,7 +81,7 @@ class RootObserver : public ViewObserver {
void OnViewDestroyed(View* view) override {
DCHECK_EQ(view, root_);
static_cast<ViewManagerClientImpl*>(
- ViewPrivate(root_).view_manager())->RemoveRoot(root_);
+ ViewPrivate(root_).view_manager())->RootDestroyed(root_);
view->RemoveObserver(this);
delete this;
}
@@ -99,6 +99,8 @@ ViewManagerClientImpl::ViewManagerClientImpl(ViewManagerDelegate* delegate,
connection_id_(0),
next_id_(1),
delegate_(delegate),
+ root_(nullptr),
+ focused_view_(nullptr),
binding_(this, handle.Pass()),
service_(binding_.client()),
delete_on_error_(delete_on_error) {
@@ -230,8 +232,8 @@ const std::string& ViewManagerClientImpl::GetEmbedderURL() const {
return creator_url_;
}
-const std::vector<View*>& ViewManagerClientImpl::GetRoots() const {
- return roots_;
+View* ViewManagerClientImpl::GetRoot() {
+ return root_;
}
View* ViewManagerClientImpl::GetViewById(Id id) {
@@ -239,6 +241,10 @@ View* ViewManagerClientImpl::GetViewById(Id id) {
return it != views_.end() ? it->second : NULL;
}
+View* ViewManagerClientImpl::GetFocusedView() {
+ return focused_view_;
+}
+
////////////////////////////////////////////////////////////////////////////////
// ViewManagerClientImpl, ViewManagerClient implementation:
@@ -248,20 +254,14 @@ void ViewManagerClientImpl::OnEmbed(
ViewDataPtr root_data,
InterfaceRequest<ServiceProvider> parent_services,
ScopedMessagePipeHandle window_manager_pipe) {
- if (!connected_) {
- connected_ = true;
- connection_id_ = connection_id;
- creator_url_ = String::From(creator_url);
- } else {
- DCHECK_EQ(connection_id_, connection_id);
- DCHECK_EQ(creator_url_, creator_url);
- }
+ DCHECK(!connected_);
+ connected_ = true;
+ connection_id_ = connection_id;
+ creator_url_ = String::From(creator_url);
- // A new root must not already exist as a root or be contained by an existing
- // hierarchy visible to this view manager.
- View* root = AddViewToViewManager(this, NULL, root_data);
- roots_.push_back(root);
- root->AddObserver(new RootObserver(root));
+ DCHECK(!root_);
+ root_ = AddViewToViewManager(this, nullptr, root_data);
+ root_->AddObserver(new RootObserver(root_));
ServiceProviderImpl* exported_services = nullptr;
scoped_ptr<ServiceProvider> remote;
@@ -274,7 +274,12 @@ void ViewManagerClientImpl::OnEmbed(
}
window_manager_.Bind(window_manager_pipe.Pass());
window_manager_.set_client(this);
- delegate_->OnEmbed(this, root, exported_services, remote.Pass());
+ // base::Unretained() is safe here as |window_manager_| is bound to our
+ // lifetime.
+ window_manager_->GetFocusedAndActiveViews(
+ base::Bind(&ViewManagerClientImpl::OnGotFocusedAndActiveViews,
+ base::Unretained(this)));
+ delegate_->OnEmbed(this, root_, exported_services, remote.Pass());
}
void ViewManagerClientImpl::OnEmbeddedAppDisconnected(Id view_id) {
@@ -386,6 +391,7 @@ void ViewManagerClientImpl::OnFocusChanged(Id old_focused_view_id,
*ViewPrivate(blurred).observers(),
OnViewFocusChanged(focused, blurred));
}
+ focused_view_ = focused;
if (focused) {
FOR_EACH_OBSERVER(ViewObserver,
*ViewPrivate(focused).observers(),
@@ -406,11 +412,9 @@ void ViewManagerClientImpl::OnConnectionError() {
////////////////////////////////////////////////////////////////////////////////
// ViewManagerClientImpl, private:
-void ViewManagerClientImpl::RemoveRoot(View* root) {
- std::vector<View*>::iterator it =
- std::find(roots_.begin(), roots_.end(), root);
- if (it != roots_.end())
- roots_.erase(it);
+void ViewManagerClientImpl::RootDestroyed(View* root) {
+ DCHECK_EQ(root, root_);
+ root_ = nullptr;
}
void ViewManagerClientImpl::OnActionCompleted(bool success) {
@@ -433,4 +437,10 @@ base::Callback<void(ErrorCode)>
base::Unretained(this));
}
+void ViewManagerClientImpl::OnGotFocusedAndActiveViews(uint32 focused_view_id,
+ uint32 active_view_id) {
+ if (GetViewById(focused_view_id) != focused_view_)
+ OnFocusChanged(focused_view_ ? focused_view_->id() : 0, focused_view_id);
+}
+
} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698