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

RemoteRWHVMac: Make querying TextInputType not be synchronous

This state can be forwarded to the RenderWidgetHostViewCocoa instead
of being queried using a synchronous callback.

Bug: 821651
Change-Id: I163946352f2f3f5d7288134dd365504d4bd04912
Reviewed-on: https://chromium-review.googlesource.com/1064980Reviewed-by: default avatarSidney San Martín <sdy@chromium.org>
Commit-Queue: ccameron <ccameron@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560904}
parent b247d53f
......@@ -16,6 +16,7 @@
#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;
......@@ -72,6 +73,9 @@ class RenderWidgetHostNSViewBridge {
// 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,
......
......@@ -44,6 +44,7 @@ class RenderWidgetHostViewNSViewBridgeLocal
void SetBackgroundColor(SkColor color) override;
void SetVisible(bool visible) override;
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,
const gfx::Range& range) override;
......@@ -225,6 +226,11 @@ void RenderWidgetHostViewNSViewBridgeLocal::CancelComposition() {
[cocoa_view_ cancelComposition];
}
void RenderWidgetHostViewNSViewBridgeLocal::SetTextInputType(
ui::TextInputType text_input_type) {
[cocoa_view_ setTextInputType:text_input_type];
}
void RenderWidgetHostViewNSViewBridgeLocal::SetTextSelection(
const base::string16& text,
size_t offset,
......
......@@ -141,10 +141,6 @@ class RenderWidgetHostNSViewClient {
virtual void OnNSViewLookUpDictionaryOverlayFromRange(
const gfx::Range& range) = 0;
// Synchronously query the text input type from the
virtual void OnNSViewSyncGetTextInputType(
ui::TextInputType* text_input_type) = 0;
// Synchronously query the character index for |root_point| and return it in
// |*index|. Sets it to UINT32_MAX if the request fails or is not completed.
virtual void OnNSViewSyncGetCharacterIndexAtPoint(
......
......@@ -18,6 +18,7 @@
#import "ui/base/cocoa/command_dispatcher.h"
#import "ui/base/cocoa/tool_tip_base_view.h"
#include "ui/base/ime/ime_text_span.h"
#include "ui/base/ime/text_input_type.h"
#include "ui/gfx/range/range.h"
namespace blink {
......@@ -114,6 +115,8 @@ struct DidOverscrollParams;
// the whole content yet.
NSRange markedRange_;
ui::TextInputType textInputType_;
// The text selection, cached from the RenderWidgetHostView. This is only ever
// updated from the renderer.
base::string16 textSelectionText_;
......@@ -172,6 +175,7 @@ struct DidOverscrollParams;
}
@property(nonatomic, assign) NSRange markedRange;
@property(nonatomic, assign) ui::TextInputType textInputType;
// Common code path for handling begin gesture events. This helper method is
// called via different codepaths based on OS version and SDK:
......
......@@ -102,8 +102,6 @@ class NoopClient : public RenderWidgetHostNSViewClient {
const gfx::PointF& root_point) override {}
void OnNSViewLookUpDictionaryOverlayFromRange(
const gfx::Range& range) override {}
void OnNSViewSyncGetTextInputType(
ui::TextInputType* text_input_type) override {}
void OnNSViewSyncGetCharacterIndexAtPoint(const gfx::PointF& root_point,
uint32_t* index) override {}
void OnNSViewSyncGetFirstRectForRange(const gfx::Range& requested_range,
......@@ -210,6 +208,7 @@ void ExtractUnderlines(NSAttributedString* string,
@implementation RenderWidgetHostViewCocoa
@synthesize markedRange = markedRange_;
@synthesize textInputType = textInputType_;
- (id)initWithClient:(RenderWidgetHostNSViewClient*)client {
self = [super initWithFrame:NSZeroRect];
......@@ -223,6 +222,7 @@ void ExtractUnderlines(NSAttributedString* string,
canBeKeyView_ = YES;
isStylusEnteringProximity_ = false;
keyboardLockActive_ = false;
textInputType_ = ui::TEXT_INPUT_TYPE_NONE;
}
return self;
}
......@@ -695,9 +695,7 @@ void ExtractUnderlines(NSAttributedString* string,
// function call.
client_->OnNSViewBeginKeyboardEvent();
ui::TextInputType textInputType = ui::TEXT_INPUT_TYPE_NONE;
client_->OnNSViewSyncGetTextInputType(&textInputType);
bool shouldAutohideCursor = textInputType != ui::TEXT_INPUT_TYPE_NONE &&
bool shouldAutohideCursor = textInputType_ != ui::TEXT_INPUT_TYPE_NONE &&
eventType == NSKeyDown &&
!(modifierFlags & NSCommandKeyMask);
......@@ -1598,9 +1596,7 @@ extern NSString* NSTextInputReplacementRangeAttributeName;
// nil when the caret is in non-editable content or password box to avoid
// making input methods do their work.
- (NSTextInputContext*)inputContext {
ui::TextInputType textInputType = ui::TEXT_INPUT_TYPE_NONE;
client_->OnNSViewSyncGetTextInputType(&textInputType);
switch (textInputType) {
switch (textInputType_) {
case ui::TEXT_INPUT_TYPE_NONE:
case ui::TEXT_INPUT_TYPE_PASSWORD:
return nil;
......@@ -1833,14 +1829,11 @@ extern NSString* NSTextInputReplacementRangeAttributeName;
- (id)validRequestorForSendType:(NSString*)sendType
returnType:(NSString*)returnType {
ui::TextInputType textInputType = ui::TEXT_INPUT_TYPE_NONE;
client_->OnNSViewSyncGetTextInputType(&textInputType);
id requestor = nil;
BOOL sendTypeIsString = [sendType isEqual:NSStringPboardType];
BOOL returnTypeIsString = [returnType isEqual:NSStringPboardType];
BOOL hasText = !textSelectionRange_.is_empty();
BOOL takesText = textInputType != ui::TEXT_INPUT_TYPE_NONE;
BOOL takesText = textInputType_ != ui::TEXT_INPUT_TYPE_NONE;
if (sendTypeIsString && hasText && !returnType) {
requestor = self;
......
......@@ -342,8 +342,6 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
const gfx::PointF& root_point) override;
void OnNSViewLookUpDictionaryOverlayFromRange(
const gfx::Range& range) override;
void OnNSViewSyncGetTextInputType(
ui::TextInputType* text_input_type) override;
void OnNSViewSyncGetCharacterIndexAtPoint(const gfx::PointF& root_point,
uint32_t* index) override;
void OnNSViewSyncGetFirstRectForRange(const gfx::Range& requested_range,
......
......@@ -452,6 +452,8 @@ void RenderWidgetHostViewMac::OnUpdateTextInputStateCalled(
if (!did_update_state)
return;
ns_view_bridge_->SetTextInputType(GetTextInputType());
// |updated_view| is the last view to change its TextInputState which can be
// used to start/stop monitoring composition info when it has a focused
// editable text input field.
......@@ -1620,11 +1622,6 @@ void RenderWidgetHostViewMac::OnNSViewLookUpDictionaryOverlayAtPoint(
target_widget_routing_id));
}
void RenderWidgetHostViewMac::OnNSViewSyncGetTextInputType(
ui::TextInputType* text_input_type) {
*text_input_type = GetTextInputType();
}
void RenderWidgetHostViewMac::OnNSViewSyncGetCharacterIndexAtPoint(
const gfx::PointF& root_point,
uint32_t* index) {
......
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