Initial work on a new <view> element backed by a mojo::View.

This CL introduces an HTMLViewElement which, when inserted into a document,
causes a mojo::View to be created and navigated to the provided URL. No
compositing is done, but the view manager handles the rendering (as I
understand it).

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/708903002
This commit is contained in:
Matt Perry 2014-11-07 14:34:07 -05:00
parent c70e474000
commit 694cabc454
15 changed files with 215 additions and 0 deletions

View File

@ -767,6 +767,8 @@ sky_core_files = [
"html/HTMLTemplateElement.h",
"html/HTMLTitleElement.cpp",
"html/HTMLTitleElement.h",
"html/HTMLIFrameElement.cpp",
"html/HTMLIFrameElement.h",
"html/ImageData.cpp",
"html/ImageData.h",
"html/PublicURLManager.cpp",
@ -1053,6 +1055,7 @@ sky_core_files = [
"rendering/RenderLineBoxList.cpp",
"rendering/RenderObject.cpp",
"rendering/RenderObjectChildList.cpp",
"rendering/RenderRemote.cpp",
"rendering/RenderReplaced.cpp",
"rendering/RenderSelectionInfo.h",
"rendering/RenderText.cpp",
@ -1224,6 +1227,7 @@ core_idl_files = get_path_info([
"html/HTMLContentElement.idl",
"html/HTMLDocument.idl",
"html/HTMLElement.idl",
"html/HTMLIFrameElement.idl",
"html/HTMLImageElement.idl",
"html/HTMLImportElement.idl",
"html/HTMLScriptElement.idl",

View File

@ -0,0 +1,65 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "core/html/HTMLIFrameElement.h"
#include "core/HTMLNames.h"
#include "core/frame/LocalFrame.h"
#include "core/html/parser/HTMLParserIdioms.h"
#include "core/loader/FrameLoaderClient.h"
#include "core/rendering/RenderRemote.h"
namespace blink {
PassRefPtr<HTMLIFrameElement> HTMLIFrameElement::create(Document& document)
{
return adoptRef(new HTMLIFrameElement(document));
}
HTMLIFrameElement::HTMLIFrameElement(Document& document)
: HTMLElement(HTMLNames::iframeTag, document)
{
}
HTMLIFrameElement::~HTMLIFrameElement()
{
}
Node::InsertionNotificationRequest HTMLIFrameElement::insertedInto(ContainerNode* insertionPoint)
{
InsertionNotificationRequest result = HTMLElement::insertedInto(insertionPoint);
if (insertionPoint->inDocument())
createView();
return result;
}
void HTMLIFrameElement::removedFrom(ContainerNode* insertionPoint)
{
HTMLElement::removedFrom(insertionPoint);
if (insertionPoint->inDocument()) {
// TODO(mpcomplete): Tear down the mojo View.
}
}
RenderObject* HTMLIFrameElement::createRenderer(RenderStyle* style)
{
return new RenderRemote(this);
}
void HTMLIFrameElement::createView()
{
String urlString = stripLeadingAndTrailingHTMLSpaces(getAttribute(HTMLNames::srcAttr));
if (urlString.isEmpty())
urlString = blankURL().string();
LocalFrame* parentFrame = document().frame();
if (!parentFrame)
return;
KURL url = document().completeURL(urlString);
parentFrame->loaderClient()->createView(url);
}
}

View File

@ -0,0 +1,36 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef HTMLIFrameElement_h
#define HTMLIFrameElement_h
#include "core/HTMLNames.h"
#include "core/dom/DOMURLUtils.h"
#include "core/dom/Document.h"
#include "core/html/HTMLElement.h"
namespace blink {
class HTMLIFrameElement : public HTMLElement {
DEFINE_WRAPPERTYPEINFO();
public:
static PassRefPtr<HTMLIFrameElement> create(Document&);
virtual ~HTMLIFrameElement();
private:
explicit HTMLIFrameElement(Document&);
virtual RenderObject* createRenderer(RenderStyle* style) override;
virtual InsertionNotificationRequest insertedInto(ContainerNode*) override;
virtual void removedFrom(ContainerNode*) override;
private:
void createView();
};
} // namespace blink
#endif // HTMLIFrameElement_h

View File

@ -0,0 +1,6 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
interface HTMLIFrameElement : HTMLElement {
};

View File

@ -4,6 +4,7 @@ fallbackInterfaceName="HTMLElement"
a interfaceName=HTMLAnchorElement
canvas
content interfaceName=HTMLContentElement
iframe interfaceName=HTMLIFrameElement
img interfaceName=HTMLImageElement, constructorNeedsCreatedByParser
import
script

View File

@ -130,6 +130,7 @@ public:
virtual void didStopLoading() override { }
virtual void loadURLExternally(const ResourceRequest&, NavigationPolicy, const String& = String()) override { }
virtual void createView(const KURL&) override {}
virtual void transitionToCommittedForNewPage() override { }

View File

@ -87,6 +87,9 @@ namespace blink {
virtual void loadURLExternally(const ResourceRequest&, NavigationPolicy, const String& suggestedName = String()) = 0;
// TODO(mpcomplete): return surface ID?
virtual void createView(const KURL&) = 0;
// Transmits the change in the set of watched CSS selectors property
// that match any element on the frame.
virtual void selectorMatchChanged(const Vector<String>& addedSelectors, const Vector<String>& removedSelectors) = 0;

View File

@ -0,0 +1,40 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "core/rendering/RenderRemote.h"
#include "core/editing/FrameSelection.h"
#include "core/html/HTMLIFrameElement.h"
#include "core/rendering/PaintInfo.h"
#include "platform/geometry/LayoutPoint.h"
namespace blink {
RenderRemote::RenderRemote(HTMLIFrameElement* view)
: RenderReplaced(view)
{
}
RenderRemote::~RenderRemote()
{
}
void RenderRemote::paintReplaced(PaintInfo& paintInfo,
const LayoutPoint& paintOffset) {
// Draw a gray background. This should be painted over by the actual
// content.
// TODO(mpcomplete): figure out what we should actually do here.
GraphicsContext* context = paintInfo.context;
IntRect paintRect = pixelSnappedIntRect(LayoutRect(
paintOffset.x(), paintOffset.y(), contentWidth(), contentHeight()));
context->setStrokeStyle(SolidStroke);
context->setStrokeColor(Color::lightGray);
context->setFillColor(Color::darkGray);
context->drawRect(paintRect);
}
} // namespace blink

View File

@ -0,0 +1,26 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef RenderRemote_h
#define RenderRemote_h
#include "core/rendering/RenderReplaced.h"
namespace blink {
class HTMLIFrameElement;
class RenderRemote : public RenderReplaced {
public:
explicit RenderRemote(HTMLIFrameElement*);
virtual ~RenderRemote();
private:
virtual LayerType layerTypeRequired() const override { return NormalLayer; }
virtual void paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset);
};
} // namespace blink
#endif // RenderRemote_h

View File

@ -70,6 +70,8 @@ public:
// frameDetached().
virtual WebFrame* createChildFrame(WebLocalFrame* parent, const WebString& frameName) { return 0; }
virtual void createChildView(const WebURL& url) { }
// This frame has been detached from the view, but has not been closed yet.
virtual void frameDetached(WebFrame*) { }

View File

@ -37,6 +37,7 @@
#include "core/events/MouseEvent.h"
#include "core/frame/FrameView.h"
#include "core/frame/Settings.h"
#include "core/html/HTMLIFrameElement.h"
#include "core/page/Chrome.h"
#include "core/page/EventHandler.h"
#include "core/page/Page.h"
@ -250,6 +251,13 @@ void FrameLoaderClientImpl::loadURLExternally(const ResourceRequest& request, Na
}
}
void FrameLoaderClientImpl::createView(const KURL& url)
{
if (m_webFrame->client()) {
m_webFrame->client()->createChildView(url);
}
}
void FrameLoaderClientImpl::selectorMatchChanged(const Vector<String>& addedSelectors, const Vector<String>& removedSelectors)
{
if (WebFrameClient* client = m_webFrame->client())

View File

@ -73,6 +73,7 @@ public:
virtual void didStopLoading() override;
virtual void progressEstimateChanged(double progressEstimate) override;
virtual void loadURLExternally(const ResourceRequest&, NavigationPolicy, const String& suggestedName = String()) override;
virtual void createView(const KURL&) override;
virtual void selectorMatchChanged(const Vector<String>& addedSelectors, const Vector<String>& removedSelectors) override;
virtual void transitionToCommittedForNewPage() override;
virtual void didChangeScrollOffset() override;

View File

@ -0,0 +1 @@
<div>This is an <iframe src="abarth.sky">iframe</iframe> element.</div>

View File

@ -151,6 +151,22 @@ blink::WebLayerTreeView* DocumentView::initializeLayerTreeView() {
return web_layer_tree_view_impl_.get();
}
void DocumentView::createChildView(const blink::WebURL& url) {
if (!root_)
return;
mojo::View* child = mojo::View::Create(root_->view_manager());
root_->AddChild(child);
// TODO(mpcomplete): actual bounds.
mojo::Rect mojo_bounds;
mojo_bounds.x = 0;
mojo_bounds.y = 50;
mojo_bounds.width = 300;
mojo_bounds.height = 100;
child->SetBounds(mojo_bounds);
child->Embed(mojo::String::From(url.string().utf8()));
}
void DocumentView::frameDetached(blink::WebFrame* frame) {
// |frame| is invalid after here.
frame->close();
@ -206,6 +222,10 @@ void DocumentView::OnViewBoundsChanged(mojo::View* view,
void DocumentView::OnViewDestroyed(mojo::View* view) {
DCHECK_EQ(view, root_);
for (auto& child : root_->children())
child->Destroy();
delete this;
}

View File

@ -69,6 +69,7 @@ class DocumentView : public mojo::InterfaceImpl<mojo::Application>,
virtual blink::WebLayerTreeView* initializeLayerTreeView();
// WebFrameClient methods:
void createChildView(const blink::WebURL&) override;
void frameDetached(blink::WebFrame*) override;
blink::WebNavigationPolicy decidePolicyForNavigation(
const blink::WebFrameClient::NavigationPolicyInfo& info) override;