Commit 72388165 authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

RemoteRWHVMac: Mojo-ify RenderWidgetHostNSViewBridge

Replace the C++ interface RenderWidgetHostNSViewBridge with an
equivalent mojo implementation.

Add required native types WebCursor and EncodedAttributedString.

Touch up RenderWidgetHostNSViewBridgeLocal's functions to match new
signatures.

Bug: 821651
Change-Id: I8e1ed2e842571ffdb28a08b1546ef5996120266a
Reviewed-on: https://chromium-review.googlesource.com/1110755Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Commit-Queue: ccameron <ccameron@chromium.org>
Cr-Commit-Position: refs/heads/master@{#571005}
parent 1fe9dde3
......@@ -2279,7 +2279,6 @@ jumbo_source_set("browser") {
sources += [
"renderer_host/popup_window_mac.h",
"renderer_host/popup_window_mac.mm",
"renderer_host/render_widget_host_ns_view_bridge.h",
"renderer_host/render_widget_host_ns_view_bridge_local.h",
"renderer_host/render_widget_host_ns_view_bridge_local.mm",
"renderer_host/render_widget_host_ns_view_client.h",
......
// 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 CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_NS_VIEW_BRIDGE_H_
#define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_NS_VIEW_BRIDGE_H_
@class RenderWidgetHostViewCocoa;
#include <memory>
#include "base/containers/flat_set.h"
#include "base/macros.h"
#include "base/optional.h"
#include "base/strings/string16.h"
#include "content/common/mac/attributed_string_coder.h"
#include "third_party/blink/public/web/web_popup_type.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/ime/text_input_type.h"
namespace gfx {
struct CALayerParams;
class Point;
class Range;
class Rect;
} // namespace gfx
namespace ui {
enum class DomCode;
} // namespace ui
namespace content {
class WebCursor;
// The interface through which RenderWidgetHostViewMac is to manipulate its
// corresponding NSView (potentially in another process).
class RenderWidgetHostNSViewBridge {
public:
RenderWidgetHostNSViewBridge() {}
virtual ~RenderWidgetHostNSViewBridge() {}
// TODO(ccameron): RenderWidgetHostViewMac and other functions currently use
// this method to communicate directly with RenderWidgetHostViewCocoa. The
// goal of this class is to eliminate this direct communication (so this
// method is expected to go away).
virtual RenderWidgetHostViewCocoa* GetRenderWidgetHostViewCocoa() = 0;
// Initialize the window as a popup (e.g, date/time picker).
virtual void InitAsPopup(const gfx::Rect& content_rect,
blink::WebPopupType popup_type) = 0;
// Disable displaying any content (including the background color). This is
// to be called on views that are to be displayed via a parent ui::Compositor.
virtual void DisableDisplay() = 0;
// Make the NSView be the first responder of its NSWindow.
virtual void MakeFirstResponder() = 0;
// Set the bounds of the NSView or its enclosing NSWindow (depending on the
// window type).
virtual void SetBounds(const gfx::Rect& rect) = 0;
// Set the contents to display in the NSView.
virtual void SetCALayerParams(const gfx::CALayerParams& ca_layer_params) = 0;
// Set the background color of the hosted CALayer.
virtual void SetBackgroundColor(SkColor color) = 0;
// Call the -[NSView setHidden:] method.
virtual void SetVisible(bool visible) = 0;
// Call the -[NSView setToolTipAtMousePoint] method.
virtual void SetTooltipText(const base::string16& display_text) = 0;
// Forward changes in ui::TextInputType.
virtual void SetTextInputType(ui::TextInputType text_input_type) = 0;
// Forward the TextInputManager::TextSelection from the renderer.
virtual void SetTextSelection(const base::string16& text,
size_t offset,
const gfx::Range& range) = 0;
// Forward the TextInputManager::CompositionRangeInfo from the renderer.
virtual void SetCompositionRangeInfo(const gfx::Range& range) = 0;
// Clear the marked range.
virtual void CancelComposition() = 0;
// Indicate if the WebContext is showing a context menu.
virtual void SetShowingContextMenu(bool showing) = 0;
// Set the cursor type to display.
virtual void DisplayCursor(const WebCursor& cursor) = 0;
// Lock or unlock the cursor.
virtual void SetCursorLocked(bool locked) = 0;
// Open the dictionary overlay for the currently selected string. This
// will roundtrip to the NSView to determine the selected range.
virtual void ShowDictionaryOverlayForSelection() = 0;
// Open the dictionary overlay for the specified string at the specified
// point.
virtual void ShowDictionaryOverlay(
const mac::AttributedStringCoder::EncodedString& encoded_string,
gfx::Point baseline_point) = 0;
// Start intercepting keyboard events.
virtual void LockKeyboard(
base::Optional<base::flat_set<ui::DomCode>> dom_codes) = 0;
// Stop intercepting keyboard events.
virtual void UnlockKeyboard() = 0;
private:
DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostNSViewBridge);
};
} // namespace content
#endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_NS_VIEW_BRIDGE_H_
......@@ -9,8 +9,8 @@
#import "base/mac/scoped_nsobject.h"
#import "content/browser/renderer_host/popup_window_mac.h"
#import "content/browser/renderer_host/render_widget_host_ns_view_bridge.h"
#import "content/browser/renderer_host/render_widget_host_view_cocoa.h"
#include "content/common/render_widget_host_ns_view.mojom.h"
#include "ui/accelerated_widget_mac/display_ca_layer_tree.h"
#include "ui/display/display_observer.h"
......@@ -19,15 +19,21 @@ namespace content {
// Bridge to a locally-hosted NSView -- this is always instantiated in the same
// process as the NSView. The caller of this interface may exist in another
// process.
class RenderWidgetHostNSViewBridgeLocal : public RenderWidgetHostNSViewBridge,
public display::DisplayObserver {
class RenderWidgetHostNSViewBridgeLocal
: public mojom::RenderWidgetHostNSViewBridge,
public display::DisplayObserver {
public:
explicit RenderWidgetHostNSViewBridgeLocal(
RenderWidgetHostNSViewClient* client);
~RenderWidgetHostNSViewBridgeLocal() override;
// RenderWidgetHostNSViewBridge implementation.
RenderWidgetHostViewCocoa* GetRenderWidgetHostViewCocoa() override;
// TODO(ccameron): RenderWidgetHostViewMac and other functions currently use
// this method to communicate directly with RenderWidgetHostViewCocoa. The
// goal of this class is to eliminate this direct communication (so this
// method is expected to go away).
RenderWidgetHostViewCocoa* GetRenderWidgetHostViewCocoa();
// mojom::RenderWidgetHostNSViewBridge implementation.
void InitAsPopup(const gfx::Rect& content_rect,
blink::WebPopupType popup_type) override;
void DisableDisplay() override;
......@@ -39,7 +45,7 @@ class RenderWidgetHostNSViewBridgeLocal : public RenderWidgetHostNSViewBridge,
void SetTooltipText(const base::string16& display_text) override;
void SetTextInputType(ui::TextInputType text_input_type) override;
void SetTextSelection(const base::string16& text,
size_t offset,
uint64_t offset,
const gfx::Range& range) override;
void SetCompositionRangeInfo(const gfx::Range& range) override;
void CancelComposition() override;
......@@ -49,8 +55,9 @@ class RenderWidgetHostNSViewBridgeLocal : public RenderWidgetHostNSViewBridge,
void ShowDictionaryOverlayForSelection() override;
void ShowDictionaryOverlay(
const mac::AttributedStringCoder::EncodedString& encoded_string,
gfx::Point baseline_point) override;
void LockKeyboard(base::Optional<base::flat_set<ui::DomCode>> codes) override;
const gfx::Point& baseline_point) override;
void LockKeyboard(
const base::Optional<std::vector<uint32_t>>& uint_dom_codes) override;
void UnlockKeyboard() override;
private:
......
......@@ -170,7 +170,7 @@ void RenderWidgetHostNSViewBridgeLocal::SetTextInputType(
void RenderWidgetHostNSViewBridgeLocal::SetTextSelection(
const base::string16& text,
size_t offset,
uint64_t offset,
const gfx::Range& range) {
[cocoa_view_ setTextSelectionText:text offset:offset range:range];
// Updates markedRange when there is no marked text so that retrieving
......@@ -217,7 +217,7 @@ void RenderWidgetHostNSViewBridgeLocal::ShowDictionaryOverlayForSelection() {
void RenderWidgetHostNSViewBridgeLocal::ShowDictionaryOverlay(
const mac::AttributedStringCoder::EncodedString& encoded_string,
gfx::Point baseline_point) {
const gfx::Point& baseline_point) {
NSAttributedString* string =
mac::AttributedStringCoder::Decode(&encoded_string);
if ([string length] == 0)
......@@ -230,7 +230,13 @@ void RenderWidgetHostNSViewBridgeLocal::ShowDictionaryOverlay(
}
void RenderWidgetHostNSViewBridgeLocal::LockKeyboard(
base::Optional<base::flat_set<ui::DomCode>> dom_codes) {
const base::Optional<std::vector<uint32_t>>& uint_dom_codes) {
base::Optional<base::flat_set<ui::DomCode>> dom_codes;
if (uint_dom_codes) {
dom_codes.emplace();
for (const auto& uint_dom_code : *uint_dom_codes)
dom_codes->insert(static_cast<ui::DomCode>(uint_dom_code));
}
[cocoa_view_ lockKeyboard:std::move(dom_codes)];
}
......
......@@ -21,6 +21,7 @@
#include "content/browser/renderer_host/render_widget_host_view_base.h"
#include "content/browser/renderer_host/text_input_manager.h"
#include "content/common/content_export.h"
#include "content/common/render_widget_host_ns_view.mojom.h"
#include "ipc/ipc_sender.h"
#include "ui/accelerated_widget_mac/accelerated_widget_mac.h"
#include "ui/accelerated_widget_mac/ca_transaction_observer.h"
......@@ -28,15 +29,6 @@
#include "ui/base/cocoa/remote_layer_api.h"
#include "ui/events/gesture_detection/filtered_gesture_provider.h"
namespace content {
class CursorManager;
class RenderWidgetHost;
class RenderWidgetHostNSViewBridge;
class RenderWidgetHostViewMac;
class WebContents;
class WebCursor;
}
namespace ui {
enum class DomCode;
class ScopedPasswordInputEnabler;
......@@ -48,6 +40,13 @@ class ScopedPasswordInputEnabler;
namespace content {
class CursorManager;
class RenderWidgetHost;
class RenderWidgetHostNSViewBridgeLocal;
class RenderWidgetHostViewMac;
class WebContents;
class WebCursor;
///////////////////////////////////////////////////////////////////////////////
// RenderWidgetHostViewMac
//
......@@ -471,8 +470,15 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
using SpeechCallback = base::OnceCallback<void(const base::string16&)>;
void GetPageTextForSpeech(SpeechCallback callback);
// Interface through which the NSView is to be manipulated.
std::unique_ptr<RenderWidgetHostNSViewBridge> ns_view_bridge_;
// Interface through which the NSView is to be manipulated. This points either
// to |ns_view_bridge_local_| or to (to-be-added) |ns_view_bridge_remote_|.
mojom::RenderWidgetHostNSViewBridge* ns_view_bridge_ = nullptr;
// If |ns_view_bridge_| is hosted in this process, then this will be non-null,
// and may be used to query the actual RenderWidgetHostViewCocoa that is being
// used for |this|. Any functionality that uses |new_view_bridge_local_| will
// not work when the RenderWidgetHostViewCocoa is hosted in an app process.
std::unique_ptr<RenderWidgetHostNSViewBridgeLocal> ns_view_bridge_local_;
// State tracked by Show/Hide/IsShowing.
bool is_visible_ = false;
......
......@@ -146,7 +146,9 @@ RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget,
this),
weak_factory_(this) {
// The NSView is on the other side of |ns_view_bridge_|.
ns_view_bridge_ = std::make_unique<RenderWidgetHostNSViewBridgeLocal>(this);
ns_view_bridge_local_ =
std::make_unique<RenderWidgetHostNSViewBridgeLocal>(this);
ns_view_bridge_ = ns_view_bridge_local_.get();
// Guess that the initial screen we will be on is the screen of the current
// window (since that's the best guess that we have, and is usually right).
......@@ -222,7 +224,9 @@ void RenderWidgetHostViewMac::SetParentUiLayer(ui::Layer* parent_ui_layer) {
}
RenderWidgetHostViewCocoa* RenderWidgetHostViewMac::cocoa_view() const {
return ns_view_bridge_->GetRenderWidgetHostViewCocoa();
if (ns_view_bridge_local_)
return ns_view_bridge_local_->GetRenderWidgetHostViewCocoa();
return nullptr;
}
void RenderWidgetHostViewMac::SetDelegate(
......@@ -608,7 +612,8 @@ void RenderWidgetHostViewMac::Destroy() {
// Destroy the brige to the NSView. Note that the NSView on the other side
// of |ns_view_bridge_| may outlive us due to other retains.
ns_view_bridge_.reset();
ns_view_bridge_ = nullptr;
ns_view_bridge_local_.reset();
// Delete the delegated frame state, which will reach back into
// host().
......@@ -1045,8 +1050,14 @@ void RenderWidgetHostViewMac::UnlockMouse() {
bool RenderWidgetHostViewMac::LockKeyboard(
base::Optional<base::flat_set<ui::DomCode>> dom_codes) {
base::Optional<std::vector<uint32_t>> uint_dom_codes;
if (dom_codes) {
uint_dom_codes.emplace();
for (const auto& dom_code : *dom_codes)
uint_dom_codes->push_back(static_cast<uint32_t>(dom_code));
}
is_keyboard_locked_ = true;
ns_view_bridge_->LockKeyboard(std::move(dom_codes));
ns_view_bridge_->LockKeyboard(uint_dom_codes);
return true;
}
......
......@@ -574,7 +574,10 @@ mojom("mojo_bindings") {
}
if (is_mac) {
sources += [ "font_loader_mac.mojom" ]
sources += [
"font_loader_mac.mojom",
"render_widget_host_ns_view.mojom",
]
}
enabled_features = []
......
......@@ -8,6 +8,10 @@ module content.mojom;
// ParamTraits for serialization. All of these should eventually be converted to
// proper mojom definitions.
// NOTE: This type is only mapped and usable on Mac.
[Native]
struct EncodedAttributedString;
[Native]
struct FrameOwnerProperties;
......@@ -39,6 +43,9 @@ struct WebPreferences;
[Native]
enum NetworkConnectionType;
[Native]
struct WebCursor;
[Native]
enum WebPopupType;
......
......@@ -12,6 +12,7 @@ public_headers = [
"//content/common/visual_properties.h",
"//content/public/common/input_event_ack_source.h",
"//content/public/common/input_event_ack_state.h",
"//content/common/cursors/webcursor.h",
"//content/common/input/synthetic_pinch_gesture_params.h",
"//content/common/input/synthetic_pointer_action_list_params.h",
"//content/common/input/synthetic_smooth_drag_gesture_params.h",
......@@ -87,6 +88,7 @@ type_mappings = [
"content.mojom.TouchAction=cc::TouchAction",
"content.mojom.TouchActionOptional=cc::TouchAction",
"content.mojom.TouchState=blink::WebTouchPoint::State",
"content.mojom.WebCursor=content::WebCursor",
"content.mojom.WebPopupType=blink::WebPopupType",
"content.mojom.WebPreferences=content::WebPreferences",
]
......@@ -5,6 +5,7 @@
mojom = "//content/common/native_types.mojom"
os_whitelist = [ "mac" ]
public_headers = [
"//content/common/mac/attributed_string_coder.h",
"//third_party/blink/public/platform/web_scrollbar_buttons_placement.h",
"//third_party/blink/public/platform/mac/web_scrollbar_theme.h",
]
......@@ -29,6 +30,7 @@ deps = [
"//url/ipc:url_ipc",
]
type_mappings = [
"content.mojom.EncodedAttributedString=::mac::AttributedStringCoder::EncodedString",
"content.mojom.ScrollerStyle=::blink::ScrollerStyle",
"content.mojom.ScrollbarButtonsPlacement=::blink::WebScrollbarButtonsPlacement",
]
// 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.
module content.mojom;
import "content/common/native_types.mojom";
import "content/common/input/input_handler.mojom";
import "mojo/public/mojom/base/string16.mojom";
import "services/ui/public/interfaces/ime/ime.mojom";
import "ui/display/mojo/display.mojom";
import "ui/events/mojo/event.mojom";
import "ui/gfx/geometry/mojo/geometry.mojom";
import "ui/gfx/mojo/ca_layer_params.mojom";
import "ui/gfx/range/mojo/range.mojom";
import "ui/platform_window/mojo/text_input_state.mojom";
// The interface through which code in the browser process, in
// RenderWidgetHostViewMac, sends messages to the app shim process, targeting
// the RenderWidgetHostViewCocoa NSView. No synchronous communication is allowed
// in this direction.
interface RenderWidgetHostNSViewBridge {
// Specify that the NSView will a popup (e.g, date/time picker) that will
// create its own NSWindow.
InitAsPopup(gfx.mojom.Rect content_rect,
content.mojom.WebPopupType popup_type);
// Disable displaying any content (including the background color). This is
// to be called on views that are to be displayed via a parent ui::Compositor.
DisableDisplay();
// Make the NSView be the first responder of its NSWindow.
MakeFirstResponder();
// Set the bounds of the NSView or its enclosing NSWindow (depending on the
// window type).
SetBounds(gfx.mojom.Rect rect);
// Set the contents to display in the NSView.
SetCALayerParams(gfx.mojom.CALayerParams ca_layer_params);
// Set the background SkColor color of the hosted CALayer.
SetBackgroundColor(uint32 color);
// Call the -[NSView setHidden:] method.
SetVisible(bool visible);
// Call the -[NSView setToolTipAtMousePoint] method.
SetTooltipText(mojo_base.mojom.String16 display_text);
// Forward changes in ui::TextInputType.
SetTextInputType(ui.mojom.TextInputType text_input_type);
// Forward the TextInputManager::TextSelection from the renderer.
SetTextSelection(mojo_base.mojom.String16 text,
uint64 offset,
gfx.mojom.Range range);
// Forward the TextInputManager::CompositionRangeInfo from the renderer.
SetCompositionRangeInfo(gfx.mojom.Range range);
// Clear the marked range.
CancelComposition();
// Indicate if the WebContext is showing a context menu or not.
SetShowingContextMenu(bool showing);
// Set the cursor type to display.
DisplayCursor(WebCursor cursor);
// Lock or unlock the cursor.
SetCursorLocked(bool locked);
// Open the dictionary overlay for the currently selected string. This
// will roundtrip to the NSView to determine the selected range.
ShowDictionaryOverlayForSelection();
// Open the dictionary overlay for the specified string at the specified
// point.
ShowDictionaryOverlay(EncodedAttributedString attributed_string,
gfx.mojom.Point baseline_point);
// Start intercepting keyboard events for the specified codes.
LockKeyboard(array<uint32>? dom_codes);
// Stop intercepting keyboard events.
UnlockKeyboard();
};
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