Commit 4f776493 authored by Biao She's avatar Biao She Committed by Commit Bot

Split ContentElement to PlatformUiElement and ContentElement

After this change, ContentElement should only be used for the main
web content. PlatformUiElement can be used to host platform UIs (such
as View on Android).


Bug: NONE
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_vr
Change-Id: If068d52d3134b5e1f70392523fdbfa4c047d1081
Reviewed-on: https://chromium-review.googlesource.com/1049961
Commit-Queue: Biao She <bshe@chromium.org>
Reviewed-by: default avatarChristopher Grant <cjgrant@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557177}
parent 85b8f517
......@@ -77,6 +77,8 @@ static_library("vr_common") {
"elements/paged_grid_layout.h",
"elements/paged_scroll_view.cc",
"elements/paged_scroll_view.h",
"elements/platform_ui_element.cc",
"elements/platform_ui_element.h",
"elements/rect.cc",
"elements/rect.h",
"elements/render_text_wrapper.cc",
......
......@@ -4,8 +4,9 @@
#include "chrome/browser/vr/elements/content_element.h"
#include "chrome/browser/vr/content_input_delegate.h"
#include "chrome/browser/vr/model/text_input_info.h"
#include "chrome/browser/vr/ui_element_renderer.h"
#include "chrome/browser/vr/text_input_delegate.h"
#include "chrome/browser/vr/ui_scene_constants.h"
#include "chrome/browser/vr/vr_gl_util.h"
#include "third_party/blink/public/platform/web_gesture_event.h"
......@@ -38,35 +39,35 @@ gfx::Vector3dF GetNormalFromTransform(const gfx::Transform& transform) {
ContentElement::ContentElement(
ContentInputDelegate* delegate,
ContentElement::ScreenBoundsChangedCallback bounds_changed_callback)
: delegate_(delegate), bounds_changed_callback_(bounds_changed_callback) {
DCHECK(delegate);
set_scrollable(true);
}
: PlatformUiElement(delegate),
bounds_changed_callback_(bounds_changed_callback) {}
ContentElement::~ContentElement() = default;
void ContentElement::Render(UiElementRenderer* renderer,
const CameraModel& model) const {
gfx::RectF copy_rect(0, 0, 1, 1);
int overlay_texture_id = overlay_texture_non_empty_ ? overlay_texture_id_ : 0;
int texture_id = texture_id_;
bool blend = true;
if (uses_quad_layer_) {
texture_id = 0;
overlay_texture_id = 0;
blend = false;
renderer->DrawTexturedQuad(0, 0, texture_location(),
model.view_proj_matrix * world_space_transform(),
copy_rect, computed_opacity(), size(),
corner_radius(), false);
return;
}
if (uses_quad_layer_ || texture_id_ || overlay_texture_id) {
unsigned int overlay_texture_id =
overlay_texture_non_empty_ ? overlay_texture_id_ : 0;
if (texture_id() || overlay_texture_id) {
renderer->DrawTexturedQuad(
texture_id, overlay_texture_id, texture_location_,
texture_id(), overlay_texture_id, texture_location(),
model.view_proj_matrix * world_space_transform(), copy_rect,
computed_opacity(), size(), corner_radius(), blend);
computed_opacity(), size(), corner_radius(), true);
}
}
void ContentElement::OnFocusChanged(bool focused) {
if (delegate_)
delegate_->OnFocusChanged(focused);
if (delegate())
delegate()->OnFocusChanged(focused);
focused_ = focused;
if (event_handlers_.focus_change)
......@@ -74,73 +75,13 @@ void ContentElement::OnFocusChanged(bool focused) {
}
void ContentElement::OnInputEdited(const EditedText& info) {
delegate_->OnWebInputEdited(info, false);
if (delegate())
delegate()->OnWebInputEdited(info, false);
}
void ContentElement::OnInputCommitted(const EditedText& info) {
delegate_->OnWebInputEdited(info, true);
}
void ContentElement::OnHoverEnter(const gfx::PointF& position) {
if (delegate_)
delegate_->OnContentEnter(position);
}
void ContentElement::OnHoverLeave() {
if (delegate_)
delegate_->OnContentLeave();
}
void ContentElement::OnMove(const gfx::PointF& position) {
if (delegate_)
delegate_->OnContentMove(position);
}
void ContentElement::OnButtonDown(const gfx::PointF& position) {
if (delegate_)
delegate_->OnContentDown(position);
}
void ContentElement::OnButtonUp(const gfx::PointF& position) {
if (delegate_)
delegate_->OnContentUp(position);
}
void ContentElement::OnFlingCancel(
std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& position) {
if (delegate_)
delegate_->OnContentFlingCancel(std::move(gesture), position);
}
void ContentElement::OnScrollBegin(
std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& position) {
if (delegate_)
delegate_->OnContentScrollBegin(std::move(gesture), position);
}
void ContentElement::OnScrollUpdate(
std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& position) {
if (delegate_)
delegate_->OnContentScrollUpdate(std::move(gesture), position);
}
void ContentElement::OnScrollEnd(
std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& position) {
if (delegate_)
delegate_->OnContentScrollEnd(std::move(gesture), position);
}
void ContentElement::SetTextureId(unsigned int texture_id) {
texture_id_ = texture_id;
}
void ContentElement::SetTextureLocation(
UiElementRenderer::TextureLocation location) {
texture_location_ = location;
if (delegate())
delegate()->OnWebInputEdited(info, true);
}
void ContentElement::SetOverlayTextureId(unsigned int texture_id) {
......@@ -244,10 +185,6 @@ bool ContentElement::OnBeginFrame(const gfx::Transform& head_pose) {
return false;
}
void ContentElement::SetDelegate(ContentInputDelegate* delegate) {
delegate_ = delegate;
}
void ContentElement::SetUsesQuadLayer(bool uses_quad_layer) {
uses_quad_layer_ = uses_quad_layer;
}
......
......@@ -6,36 +6,30 @@
#define CHROME_BROWSER_VR_ELEMENTS_CONTENT_ELEMENT_H_
#include "base/macros.h"
#include "chrome/browser/vr/content_input_delegate.h"
#include "chrome/browser/vr/elements/ui_element.h"
#include "chrome/browser/vr/text_input_delegate.h"
#include "chrome/browser/vr/elements/platform_ui_element.h"
#include "chrome/browser/vr/ui_element_renderer.h"
namespace vr {
class ContentElement : public UiElement {
class ContentInputDelegate;
class TextInputDelegate;
// This element hosts the texture of a web page and surfaces all frames of the
// web page to VR. It also dispatches events to the page it hosts.
// It may also surface frames of overlays on a web page which usually displayed
// by Chrome (such as infobar after download a file).
// If quad layer is set, it stops surface frames of web page but instead draws
// transparent in UI. So the web page in quad layer can be later composited to
// the UI.
class ContentElement : public PlatformUiElement {
public:
typedef typename base::Callback<void(const gfx::SizeF&)>
typedef typename base::RepeatingCallback<void(const gfx::SizeF&)>
ScreenBoundsChangedCallback;
ContentElement(ContentInputDelegate* delegate, ScreenBoundsChangedCallback);
~ContentElement() override;
void OnHoverEnter(const gfx::PointF& position) override;
void OnHoverLeave() override;
void OnMove(const gfx::PointF& position) override;
void OnButtonDown(const gfx::PointF& position) override;
void OnButtonUp(const gfx::PointF& position) override;
void OnFlingCancel(std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& position) override;
void OnScrollBegin(std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& position) override;
void OnScrollUpdate(std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& position) override;
void OnScrollEnd(std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& position) override;
bool OnBeginFrame(const gfx::Transform& head_pose) override;
void Render(UiElementRenderer* renderer,
const CameraModel& model) const final;
void OnFocusChanged(bool focused) override;
......@@ -45,24 +39,17 @@ class ContentElement : public UiElement {
void RequestUnfocus() override;
void UpdateInput(const EditedText& info) override;
void SetTextureId(unsigned int texture_id);
void SetTextureLocation(UiElementRenderer::TextureLocation location);
void SetOverlayTextureId(unsigned int texture_id);
void SetOverlayTextureLocation(UiElementRenderer::TextureLocation location);
void SetOverlayTextureEmpty(bool empty);
bool GetOverlayTextureEmpty();
void SetProjectionMatrix(const gfx::Transform& matrix);
void SetTextInputDelegate(TextInputDelegate* text_input_delegate);
void SetDelegate(ContentInputDelegate* delegate);
void SetUsesQuadLayer(bool uses_quad_layer);
private:
ContentInputDelegate* delegate_ = nullptr;
TextInputDelegate* text_input_delegate_ = nullptr;
ScreenBoundsChangedCallback bounds_changed_callback_;
unsigned int texture_id_ = 0;
UiElementRenderer::TextureLocation texture_location_ =
UiElementRenderer::kTextureLocationExternal;
unsigned int overlay_texture_id_ = 0;
bool overlay_texture_non_empty_ = false;
UiElementRenderer::TextureLocation overlay_texture_location_ =
......
// Copyright 2018 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 "chrome/browser/vr/elements/content_element.h"
#include "chrome/browser/vr/content_input_delegate.h"
#include "third_party/blink/public/platform/web_gesture_event.h"
#include "ui/gfx/geometry/rect_f.h"
namespace vr {
PlatformUiElement::PlatformUiElement(ContentInputDelegate* delegate)
: delegate_(delegate) {
DCHECK(delegate);
set_scrollable(true);
}
PlatformUiElement::~PlatformUiElement() = default;
void PlatformUiElement::Render(UiElementRenderer* renderer,
const CameraModel& model) const {
if (texture_id_) {
gfx::RectF copy_rect(0, 0, 1, 1);
renderer->DrawTexturedQuad(texture_id_, 0, texture_location_,
model.view_proj_matrix * world_space_transform(),
copy_rect, computed_opacity(), size(),
corner_radius(), true);
}
}
void PlatformUiElement::OnHoverEnter(const gfx::PointF& position) {
if (delegate_)
delegate_->OnContentEnter(position);
}
void PlatformUiElement::OnHoverLeave() {
if (delegate_)
delegate_->OnContentLeave();
}
void PlatformUiElement::OnMove(const gfx::PointF& position) {
if (delegate_)
delegate_->OnContentMove(position);
}
void PlatformUiElement::OnButtonDown(const gfx::PointF& position) {
if (delegate_)
delegate_->OnContentDown(position);
}
void PlatformUiElement::OnButtonUp(const gfx::PointF& position) {
if (delegate_)
delegate_->OnContentUp(position);
}
void PlatformUiElement::OnFlingCancel(
std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& position) {
if (delegate_)
delegate_->OnContentFlingCancel(std::move(gesture), position);
}
void PlatformUiElement::OnScrollBegin(
std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& position) {
if (delegate_)
delegate_->OnContentScrollBegin(std::move(gesture), position);
}
void PlatformUiElement::OnScrollUpdate(
std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& position) {
if (delegate_)
delegate_->OnContentScrollUpdate(std::move(gesture), position);
}
void PlatformUiElement::OnScrollEnd(
std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& position) {
if (delegate_)
delegate_->OnContentScrollEnd(std::move(gesture), position);
}
void PlatformUiElement::SetTextureId(unsigned int texture_id) {
texture_id_ = texture_id;
}
void PlatformUiElement::SetTextureLocation(
UiElementRenderer::TextureLocation location) {
texture_location_ = location;
}
void PlatformUiElement::SetDelegate(ContentInputDelegate* delegate) {
delegate_ = delegate;
}
} // namespace vr
// Copyright 2018 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 CHROME_BROWSER_VR_ELEMENTS_PLATFORM_UI_ELEMENT_H_
#define CHROME_BROWSER_VR_ELEMENTS_PLATFORM_UI_ELEMENT_H_
#include "base/macros.h"
#include "chrome/browser/vr/elements/ui_element.h"
#include "chrome/browser/vr/ui_element_renderer.h"
namespace vr {
class ContentInputDelegate;
// This element hosts the texture of a platform UI and surfaces all frames of
// the UI to VR. For example, on Android, any views UI can be drawn to a texture
// and then displayed by this element in VR.
// It also dispatches events to the platform UI.
class PlatformUiElement : public UiElement {
public:
explicit PlatformUiElement(ContentInputDelegate* delegate);
~PlatformUiElement() override;
void OnHoverEnter(const gfx::PointF& position) override;
void OnHoverLeave() override;
void OnMove(const gfx::PointF& position) override;
void OnButtonDown(const gfx::PointF& position) override;
void OnButtonUp(const gfx::PointF& position) override;
void OnFlingCancel(std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& position) override;
void OnScrollBegin(std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& position) override;
void OnScrollUpdate(std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& position) override;
void OnScrollEnd(std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& position) override;
void Render(UiElementRenderer* renderer,
const CameraModel& model) const override;
void SetTextureId(unsigned int texture_id);
void SetTextureLocation(UiElementRenderer::TextureLocation location);
void SetDelegate(ContentInputDelegate* delegate);
protected:
ContentInputDelegate* delegate() const { return delegate_; }
unsigned int texture_id() const { return texture_id_; }
UiElementRenderer::TextureLocation texture_location() const {
return texture_location_;
}
private:
ContentInputDelegate* delegate_ = nullptr;
unsigned int texture_id_ = 0;
UiElementRenderer::TextureLocation texture_location_ =
UiElementRenderer::kTextureLocationExternal;
DISALLOW_COPY_AND_ASSIGN(PlatformUiElement);
};
} // namespace vr
#endif // CHROME_BROWSER_VR_ELEMENTS_PLATFORM_UI_ELEMENT_H_
......@@ -38,6 +38,7 @@
#include "chrome/browser/vr/elements/oval.h"
#include "chrome/browser/vr/elements/paged_grid_layout.h"
#include "chrome/browser/vr/elements/paged_scroll_view.h"
#include "chrome/browser/vr/elements/platform_ui_element.h"
#include "chrome/browser/vr/elements/rect.h"
#include "chrome/browser/vr/elements/repositioner.h"
#include "chrome/browser/vr/elements/resizer.h"
......@@ -706,11 +707,10 @@ std::unique_ptr<UiElement> CreateHostedUi(
UiBrowserInterface* browser,
ContentInputDelegate* content_input_delegate,
UiElementName name,
UiElementName content_name,
UiElementName element_name,
float distance) {
auto hosted_ui =
Create<ContentElement>(content_name, kPhaseForeground,
content_input_delegate, base::DoNothing());
auto hosted_ui = Create<PlatformUiElement>(element_name, kPhaseForeground,
content_input_delegate);
hosted_ui->SetSize(kContentWidth * kHostedUiWidthRatio,
kContentHeight * kHostedUiHeightRatio);
// The hosted UI doesn't steal focus so that clikcing on an autofill
......@@ -722,16 +722,16 @@ std::unique_ptr<UiElement> CreateHostedUi(
hosted_ui->SetTranslate(0, 0, kHostedUiShadowOffset);
hosted_ui->AddBinding(VR_BIND_FUNC(
ContentInputDelegatePtr, Model, model, model->hosted_platform_ui.delegate,
ContentElement, hosted_ui.get(), SetDelegate));
PlatformUiElement, hosted_ui.get(), SetDelegate));
hosted_ui->AddBinding(VR_BIND_FUNC(
unsigned int, Model, model, model->hosted_platform_ui.texture_id,
ContentElement, hosted_ui.get(), SetTextureId));
PlatformUiElement, hosted_ui.get(), SetTextureId));
hosted_ui->AddBinding(std::make_unique<Binding<bool>>(
VR_BIND_LAMBDA(
[](Model* m) { return m->hosted_platform_ui.hosted_ui_enabled; },
base::Unretained(model)),
VR_BIND_LAMBDA(
[](ContentElement* dialog, const bool& enabled) {
[](PlatformUiElement* dialog, const bool& enabled) {
dialog->set_requires_layout(enabled);
dialog->set_hit_testable(enabled);
},
......@@ -750,7 +750,8 @@ std::unique_ptr<UiElement> CreateHostedUi(
},
base::Unretained(model)),
base::BindRepeating(
[](ContentElement* dialog, const std::pair<bool, gfx::SizeF>& value) {
[](PlatformUiElement* dialog,
const std::pair<bool, gfx::SizeF>& value) {
if (!value.first && value.second.width() > 0) {
float ratio = static_cast<float>(value.second.height()) /
value.second.width();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment