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

Side by Side Diff: blimp/client/core/render_widget/blimp_document_manager.cc

Issue 2382733007: Add BlimpDocument, pull out functions in BlimpCompositor. (Closed)
Patch Set: Fix linux client. Created 4 years, 2 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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 "blimp/client/core/render_widget/blimp_document_manager.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h"
9 #include "blimp/client/core/render_widget/blimp_document.h"
10 #include "cc/proto/compositor_message.pb.h"
11
12 namespace blimp {
13 namespace client {
14
15 BlimpDocumentManager::BlimpDocumentManager(
16 int blimp_contents_id,
17 RenderWidgetFeature* render_widget_feature,
18 BlimpCompositorDependencies* compositor_dependencies)
19 : blimp_contents_id_(blimp_contents_id),
20 render_widget_feature_(render_widget_feature),
21 visible_(false),
22 layer_(cc::Layer::Create()),
23 active_document_(nullptr),
24 compositor_dependencies_(compositor_dependencies) {
25 DCHECK(render_widget_feature_);
26 DCHECK(compositor_dependencies_);
27
28 render_widget_feature_->SetDelegate(blimp_contents_id_, this);
29 }
30
31 BlimpDocumentManager::~BlimpDocumentManager() {
32 render_widget_feature_->RemoveDelegate(blimp_contents_id_);
33 }
34
35 void BlimpDocumentManager::SetVisible(bool visible) {
36 visible_ = visible;
37 if (active_document_)
38 active_document_->GetCompositor()->SetVisible(visible_);
39 }
40
41 bool BlimpDocumentManager::OnTouchEvent(const ui::MotionEvent& motion_event) {
42 if (active_document_)
43 return active_document_->GetCompositor()->OnTouchEvent(motion_event);
44 return false;
45 }
46
47 void BlimpDocumentManager::NotifyWhenDonePendingCommits(
48 base::Closure callback) {
49 if (!active_document_ || !visible_) {
50 callback.Run();
51 return;
52 }
53
54 active_document_->GetCompositor()->NotifyWhenDonePendingCommits(callback);
55 }
56
57 std::unique_ptr<BlimpDocument> BlimpDocumentManager::CreateBlimpDocument(
58 int render_widget_id,
59 BlimpCompositorDependencies* compositor_dependencies) {
60 return base::MakeUnique<BlimpDocument>(render_widget_id,
61 compositor_dependencies, this);
62 }
63
64 void BlimpDocumentManager::OnRenderWidgetCreated(int render_widget_id) {
65 CHECK(!GetDocument(render_widget_id));
66
67 documents_[render_widget_id] =
68 CreateBlimpDocument(render_widget_id, compositor_dependencies_);
69 }
70
71 void BlimpDocumentManager::OnRenderWidgetInitialized(int render_widget_id) {
72 if (active_document_ &&
73 active_document_->render_widget_id() == render_widget_id)
74 return;
75
76 // Detach the content layer from the old compositor.
77 layer_->RemoveAllChildren();
78
79 if (active_document_) {
80 VLOG(1) << "Hiding currently active compositor for render widget: "
81 << active_document_->render_widget_id();
82 active_document_->GetCompositor()->SetVisible(false);
83 }
84
85 active_document_ = GetDocument(render_widget_id);
86 CHECK(active_document_);
87
88 active_document_->GetCompositor()->SetVisible(visible_);
89 layer_->AddChild(active_document_->GetCompositor()->layer());
90 }
91
92 void BlimpDocumentManager::OnRenderWidgetDeleted(int render_widget_id) {
93 DocumentMap::const_iterator it = documents_.find(render_widget_id);
94 CHECK(it != documents_.end());
95
96 // Reset the |active_document_| if that is what we're destroying right now.
97 if (active_document_ == it->second.get()) {
98 layer_->RemoveAllChildren();
99 active_document_ = nullptr;
100 }
101
102 documents_.erase(it);
103 }
104
105 void BlimpDocumentManager::OnCompositorMessageReceived(
106 int render_widget_id,
107 std::unique_ptr<cc::proto::CompositorMessage> message) {
108 BlimpDocument* document = GetDocument(render_widget_id);
109 BlimpCompositor* compositor = document->GetCompositor();
110
111 CHECK(compositor);
112 compositor->OnCompositorMessageReceived(std::move(message));
113 }
114
115 void BlimpDocumentManager::SendWebGestureEvent(
116 int render_widget_id,
117 const blink::WebGestureEvent& gesture_event) {
118 render_widget_feature_->SendWebGestureEvent(blimp_contents_id_,
119 render_widget_id, gesture_event);
120 }
121
122 void BlimpDocumentManager::SendCompositorMessage(
123 int render_widget_id,
124 const cc::proto::CompositorMessage& message) {
125 render_widget_feature_->SendCompositorMessage(blimp_contents_id_,
126 render_widget_id, message);
127 }
128
129 BlimpDocument* BlimpDocumentManager::GetDocument(int render_widget_id) {
130 DocumentMap::const_iterator it = documents_.find(render_widget_id);
131 if (it == documents_.end())
132 return nullptr;
133 return it->second.get();
134 }
135
136 } // namespace client
137 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698