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

Side by Side Diff: mojo/examples/html_viewer/html_document_view.cc

Issue 383123006: Preliminary interactive layout of window manager's demo_launcher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: make NativeWidgetViewManager observer cleanup consistent with other classes Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
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
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
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 // Overridden from NodeObserver:
sky 2014/07/15 00:07:49 Style guide says not to duplicate comments like th
hansmuller 2014/07/15 00:27:43 Done.
192 void HTMLDocumentView::OnNodeBoundsChanged(view_manager::Node* node,
193 const gfx::Rect& old_bounds,
194 const gfx::Rect& new_bounds) {
195 DCHECK_EQ(node, root_);
196 web_view_->resize(node->bounds().size());
197 }
198
199 // Overridden from NodeObserver:
200 void HTMLDocumentView::OnNodeDestroying(view_manager::Node* node) {
201 DCHECK_EQ(node, root_);
202 node->RemoveObserver(this);
sky 2014/07/15 00:07:49 Shouldn't you set root_ to NULL here too? This com
hansmuller 2014/07/15 00:27:43 That implies that other NodeObserver methods can't
sky 2014/07/15 04:08:37 By adding this override you're saying root_ may be
203 }
204
187 void HTMLDocumentView::Repaint() { 205 void HTMLDocumentView::Repaint() {
188 repaint_pending_ = false; 206 repaint_pending_ = false;
189 207
190 web_view_->animate(0.0); 208 web_view_->animate(0.0);
191 web_view_->layout(); 209 web_view_->layout();
192 210
193 int width = web_view_->size().width; 211 int width = web_view_->size().width;
194 int height = web_view_->size().height; 212 int height = web_view_->size().height;
195 213
196 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(SkCanvas::NewRaster( 214 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(SkCanvas::NewRaster(
197 SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType))); 215 SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType)));
198 216
199 web_view_->paint(canvas.get(), gfx::Rect(0, 0, width, height)); 217 web_view_->paint(canvas.get(), gfx::Rect(0, 0, width, height));
200 218
201 view_->SetContents(canvas->getDevice()->accessBitmap(false)); 219 view_->SetContents(canvas->getDevice()->accessBitmap(false));
202 } 220 }
203 221
204 } // namespace examples 222 } // namespace examples
205 } // namespace mojo 223 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/examples/html_viewer/html_document_view.h ('k') | mojo/examples/media_viewer/media_viewer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698