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 "mojo/examples/html_viewer/html_document_view.h" | 5 #include "mojo/examples/html_viewer/html_document_view.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 return false; | 73 return false; |
74 } | 74 } |
75 | 75 |
76 } // namespace | 76 } // namespace |
77 | 77 |
78 HTMLDocumentView::HTMLDocumentView(ServiceProvider* service_provider, | 78 HTMLDocumentView::HTMLDocumentView(ServiceProvider* service_provider, |
79 view_manager::ViewManager* view_manager) | 79 view_manager::ViewManager* view_manager) |
80 : view_manager_(view_manager), | 80 : view_manager_(view_manager), |
81 view_(view_manager::View::Create(view_manager_)), | 81 view_(view_manager::View::Create(view_manager_)), |
82 web_view_(NULL), | 82 web_view_(NULL), |
| 83 root_(NULL), |
83 repaint_pending_(false), | 84 repaint_pending_(false), |
84 navigator_host_(service_provider), | 85 navigator_host_(service_provider), |
85 weak_factory_(this) { | 86 weak_factory_(this) { |
86 view_->AddObserver(this); | 87 view_->AddObserver(this); |
87 } | 88 } |
88 | 89 |
89 HTMLDocumentView::~HTMLDocumentView() { | 90 HTMLDocumentView::~HTMLDocumentView() { |
90 view_->RemoveObserver(this); | 91 view_->RemoveObserver(this); |
91 | |
92 if (web_view_) | 92 if (web_view_) |
93 web_view_->close(); | 93 web_view_->close(); |
| 94 if (root_) |
| 95 root_->RemoveObserver(this); |
94 } | 96 } |
95 | 97 |
96 void HTMLDocumentView::AttachToNode(view_manager::Node* node) { | 98 void HTMLDocumentView::AttachToNode(view_manager::Node* node) { |
97 node->SetActiveView(view_); | 99 root_ = node; |
| 100 root_->SetActiveView(view_); |
98 view_->SetColor(SK_ColorCYAN); // Dummy background color. | 101 view_->SetColor(SK_ColorCYAN); // Dummy background color. |
99 | 102 |
100 web_view_ = blink::WebView::create(this); | 103 web_view_ = blink::WebView::create(this); |
101 ConfigureSettings(web_view_->settings()); | 104 ConfigureSettings(web_view_->settings()); |
102 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); | 105 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); |
| 106 web_view_->resize(root_->bounds().size()); |
103 | 107 |
104 web_view_->resize(gfx::Size(node->bounds().size())); | 108 root_->AddObserver(this); |
105 } | 109 } |
106 | 110 |
107 void HTMLDocumentView::Load(URLResponsePtr response) { | 111 void HTMLDocumentView::Load(URLResponsePtr response) { |
108 DCHECK(web_view_); | 112 DCHECK(web_view_); |
109 | 113 |
110 GURL url(response->url); | 114 GURL url(response->url); |
111 | 115 |
112 WebURLRequestExtraData* extra_data = new WebURLRequestExtraData; | 116 WebURLRequestExtraData* extra_data = new WebURLRequestExtraData; |
113 extra_data->synthetic_response = response.Pass(); | 117 extra_data->synthetic_response = response.Pass(); |
114 | 118 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 181 |
178 void HTMLDocumentView::OnViewInputEvent(view_manager::View* view, | 182 void HTMLDocumentView::OnViewInputEvent(view_manager::View* view, |
179 const EventPtr& event) { | 183 const EventPtr& event) { |
180 scoped_ptr<blink::WebInputEvent> web_event = | 184 scoped_ptr<blink::WebInputEvent> web_event = |
181 TypeConverter<EventPtr, scoped_ptr<blink::WebInputEvent> >::ConvertTo( | 185 TypeConverter<EventPtr, scoped_ptr<blink::WebInputEvent> >::ConvertTo( |
182 event); | 186 event); |
183 if (web_event) | 187 if (web_event) |
184 web_view_->handleInputEvent(*web_event); | 188 web_view_->handleInputEvent(*web_event); |
185 } | 189 } |
186 | 190 |
| 191 void HTMLDocumentView::OnNodeBoundsChanged(view_manager::Node* node, |
| 192 const gfx::Rect& old_bounds, |
| 193 const gfx::Rect& new_bounds) { |
| 194 DCHECK_EQ(node, root_); |
| 195 web_view_->resize(node->bounds().size()); |
| 196 } |
| 197 |
| 198 void HTMLDocumentView::OnNodeDestroyed(view_manager::Node* node) { |
| 199 DCHECK_EQ(node, root_); |
| 200 node->RemoveObserver(this); |
| 201 root_ = NULL; |
| 202 } |
| 203 |
187 void HTMLDocumentView::Repaint() { | 204 void HTMLDocumentView::Repaint() { |
188 repaint_pending_ = false; | 205 repaint_pending_ = false; |
189 | 206 |
190 web_view_->animate(0.0); | 207 web_view_->animate(0.0); |
191 web_view_->layout(); | 208 web_view_->layout(); |
192 | 209 |
193 int width = web_view_->size().width; | 210 int width = web_view_->size().width; |
194 int height = web_view_->size().height; | 211 int height = web_view_->size().height; |
195 | 212 |
196 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(SkCanvas::NewRaster( | 213 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(SkCanvas::NewRaster( |
197 SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType))); | 214 SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType))); |
198 | 215 |
199 web_view_->paint(canvas.get(), gfx::Rect(0, 0, width, height)); | 216 web_view_->paint(canvas.get(), gfx::Rect(0, 0, width, height)); |
200 | 217 |
201 view_->SetContents(canvas->getDevice()->accessBitmap(false)); | 218 view_->SetContents(canvas->getDevice()->accessBitmap(false)); |
202 } | 219 } |
203 | 220 |
204 } // namespace examples | 221 } // namespace examples |
205 } // namespace mojo | 222 } // namespace mojo |
OLD | NEW |