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

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: Remove Webkit DEPS modification. 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 document_id,
59 BlimpCompositorDependencies* compositor_dependencies) {
60 return base::MakeUnique<BlimpDocument>(document_id, compositor_dependencies,
61 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_ && active_document_->document_id() == render_widget_id)
73 return;
74
75 // Detach the content layer from the old compositor.
76 layer_->RemoveAllChildren();
77
78 if (active_document_) {
79 VLOG(1) << "Hiding currently active compositor for render widget: "
80 << active_document_->document_id();
81 active_document_->GetCompositor()->SetVisible(false);
82 }
83
84 active_document_ = GetDocument(render_widget_id);
85 CHECK(active_document_);
86
87 active_document_->GetCompositor()->SetVisible(visible_);
88 layer_->AddChild(active_document_->GetCompositor()->layer());
89 }
90
91 void BlimpDocumentManager::OnRenderWidgetDeleted(int render_widget_id) {
92 DocumentMap::const_iterator it = documents_.find(render_widget_id);
93 CHECK(it != documents_.end());
94
95 // Reset the |active_document_| if that is what we're destroying right now.
96 if (active_document_ == it->second.get()) {
97 layer_->RemoveAllChildren();
98 active_document_ = nullptr;
99 }
100
101 documents_.erase(it);
102 }
103
104 void BlimpDocumentManager::OnCompositorMessageReceived(
105 int render_widget_id,
106 std::unique_ptr<cc::proto::CompositorMessage> message) {
107 BlimpDocument* document = GetDocument(render_widget_id);
108 BlimpCompositor* compositor = document->GetCompositor();
109
110 CHECK(compositor);
111 compositor->OnCompositorMessageReceived(std::move(message));
112 }
113
114 void BlimpDocumentManager::SendWebGestureEvent(
115 int document_id,
116 const blink::WebGestureEvent& gesture_event) {
117 render_widget_feature_->SendWebGestureEvent(blimp_contents_id_, document_id,
118 gesture_event);
119 }
120
121 void BlimpDocumentManager::SendCompositorMessage(
122 int document_id,
123 const cc::proto::CompositorMessage& message) {
124 render_widget_feature_->SendCompositorMessage(blimp_contents_id_, document_id,
125 message);
126 }
127
128 BlimpDocument* BlimpDocumentManager::GetDocument(int document_id) {
129 DocumentMap::const_iterator it = documents_.find(document_id);
130 if (it == documents_.end())
131 return nullptr;
132 return it->second.get();
133 }
134
135 } // namespace client
136 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698