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

RemoteRWHVMac: Add speech API and a band-aid for accessibility

Add methods on RWHNSViewClient to call into the static speech methods
of TextServicesContextMenu.

Add a call to RWHNSViewClient to query if there exists a RenderViewHost
for the current view's RenderWidgetHost, since that query is the only
piece left missing to allow -[RWHVCocoa validateUserInterfaceItem] to
not depend on RWHVMac.

Make RWHVCocoa query the BrowserAccessibilityManager via the
RHWNSViewClient interface, to eliminate another source of direct
calls into RWHVMac. This is explicitly temporary, as we will need to
come up with an accessibility solution for the AppShim process.

Bug: 821651
Change-Id: I568ed06a0bcbc0384702f494e06238fa635139e4
Reviewed-on: https://chromium-review.googlesource.com/1004444Reviewed-by: default avatarccameron <ccameron@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Commit-Queue: ccameron <ccameron@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549807}
parent 04497dc5
......@@ -24,6 +24,16 @@ class RenderWidgetHostNSViewClient {
// RenderWidgetHostNSViewBridge, this method is to be removed.
virtual RenderWidgetHostViewMac* GetRenderWidgetHostViewMac() = 0;
// Return the RenderWidget's BrowserAccessibilityManager.
// TODO(ccameron): This returns nullptr for non-local NSViews. A scheme for
// non-local accessibility needs to be developed.
virtual BrowserAccessibilityManager* GetRootBrowserAccessibilityManager() = 0;
// Synchronously query if there exists a RenderViewHost for the corresponding
// RenderWidgetHostView's RenderWidgetHost, and store the result in
// |*is_render_view|.
virtual void OnNSViewSyncIsRenderViewHost(bool* is_render_view) = 0;
// Indicates that the RenderWidgetHost is to shut down.
virtual void OnNSViewRequestShutdown() = 0;
......@@ -115,6 +125,17 @@ class RenderWidgetHostNSViewClient {
virtual void OnNSViewPasteAndMatchStyle() = 0;
virtual void OnNSViewSelectAll() = 0;
// Speak the selected text of the appropriate RenderWidgetHostView using
// TextServicesContextMenu.
virtual void OnNSViewSpeakSelection() = 0;
// Stop speaking using TextServicesContextMenu.
virtual void OnNSViewStopSpeaking() = 0;
// Synchronously query if TextServicesContextMenu is currently speaking and
// store the result in |*is_speaking|.
virtual void OnNSViewSyncIsSpeaking(bool* is_speaking) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostNSViewClient);
};
......
......@@ -17,20 +17,13 @@
#import "content/browser/cocoa/system_hotkey_helper_mac.h"
#import "content/browser/cocoa/system_hotkey_map.h"
#include "content/browser/renderer_host/input/web_input_event_builders_mac.h"
#include "content/browser/renderer_host/render_view_host_delegate.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/browser/renderer_host/render_widget_host_input_event_router.h"
#include "content/browser/renderer_host/render_widget_host_view_mac.h"
#import "content/browser/renderer_host/render_widget_host_view_mac_editcommand_helper.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_plugin_guest_manager.h"
#import "content/public/browser/render_widget_host_view_mac_delegate.h"
#include "content/public/browser/web_contents.h"
#import "ui/base/clipboard/clipboard_util_mac.h"
#import "ui/base/cocoa/appkit_utils.h"
#include "ui/base/cocoa/cocoa_base_utils.h"
#include "ui/base/cocoa/text_services_context_menu.h"
#include "ui/display/screen.h"
#include "ui/events/event_utils.h"
#include "ui/gfx/mac/coordinate_conversion.h"
......@@ -39,13 +32,11 @@ using content::BrowserAccessibility;
using content::BrowserAccessibilityManager;
using content::EditCommand;
using content::NativeWebKeyboardEvent;
using content::RenderViewHost;
using content::RenderWidgetHostImpl;
using content::RenderWidgetHostNSViewClient;
using content::RenderWidgetHostView;
using content::RenderWidgetHostViewMac;
using content::RenderWidgetHostViewMacEditCommandHelper;
using content::WebContents;
using content::WebGestureEventBuilder;
using content::WebMouseEventBuilder;
using content::WebMouseWheelEventBuilder;
......@@ -63,21 +54,6 @@ BOOL EventIsReservedBySystem(NSEvent* event) {
return helper->map()->IsEventReserved(event);
}
RenderWidgetHostView* GetRenderWidgetHostViewToUse(
RenderWidgetHostViewMac* render_widget_host_view) {
WebContents* web_contents = render_widget_host_view->GetWebContents();
if (!web_contents)
return render_widget_host_view;
content::BrowserPluginGuestManager* guest_manager =
web_contents->GetBrowserContext()->GetGuestManager();
if (!guest_manager)
return render_widget_host_view;
content::WebContents* guest = guest_manager->GetFullPageGuest(web_contents);
if (!guest)
return render_widget_host_view;
return guest->GetRenderWidgetHostView();
}
// TODO(suzhe): Upstream this function.
blink::WebColor WebColorFromNSColor(NSColor* color) {
CGFloat r, g, b, a;
......@@ -1198,12 +1174,16 @@ void ExtractUnderlines(NSAttributedString* string,
return valid;
}
bool is_render_view = false;
client_->OnNSViewSyncIsRenderViewHost(&is_render_view);
bool is_speaking = false;
client_->OnNSViewSyncIsSpeaking(&is_speaking);
SEL action = [item action];
BOOL is_render_view =
RenderViewHost::From(renderWidgetHostView_->host()) != nullptr;
if (action == @selector(stopSpeaking:))
return is_render_view && ui::TextServicesContextMenu::IsSpeaking();
return is_render_view && is_speaking;
if (action == @selector(startSpeaking:))
return is_render_view;
......@@ -1243,7 +1223,7 @@ void ExtractUnderlines(NSAttributedString* string,
- (id)accessibilityAttributeValue:(NSString*)attribute {
BrowserAccessibilityManager* manager =
renderWidgetHostView_->host()->GetRootBrowserAccessibilityManager();
client_->GetRootBrowserAccessibilityManager();
// Contents specifies document view of RenderWidgetHostViewCocoa provided by
// BrowserAccessibilityManager. Children includes all subviews in addition to
......@@ -1269,7 +1249,7 @@ void ExtractUnderlines(NSAttributedString* string,
- (id)accessibilityHitTest:(NSPoint)point {
BrowserAccessibilityManager* manager =
renderWidgetHostView_->host()->GetRootBrowserAccessibilityManager();
client_->GetRootBrowserAccessibilityManager();
if (!manager)
return self;
NSPoint pointInWindow =
......@@ -1284,13 +1264,13 @@ void ExtractUnderlines(NSAttributedString* string,
- (BOOL)accessibilityIsIgnored {
BrowserAccessibilityManager* manager =
renderWidgetHostView_->host()->GetRootBrowserAccessibilityManager();
client_->GetRootBrowserAccessibilityManager();
return !manager;
}
- (NSUInteger)accessibilityGetIndexOf:(id)child {
BrowserAccessibilityManager* manager =
renderWidgetHostView_->host()->GetRootBrowserAccessibilityManager();
client_->GetRootBrowserAccessibilityManager();
// Only child is root.
if (manager && ToBrowserAccessibilityCocoa(manager->GetRoot()) == child) {
return 0;
......@@ -1301,7 +1281,7 @@ void ExtractUnderlines(NSAttributedString* string,
- (id)accessibilityFocusedUIElement {
BrowserAccessibilityManager* manager =
renderWidgetHostView_->host()->GetRootBrowserAccessibilityManager();
client_->GetRootBrowserAccessibilityManager();
if (manager) {
BrowserAccessibility* focused_item = manager->GetFocus();
DCHECK(focused_item);
......@@ -1750,11 +1730,11 @@ extern NSString* NSTextInputReplacementRangeAttributeName;
}
- (void)startSpeaking:(id)sender {
GetRenderWidgetHostViewToUse(renderWidgetHostView_)->SpeakSelection();
client_->OnNSViewSpeakSelection();
}
- (void)stopSpeaking:(id)sender {
ui::TextServicesContextMenu::StopSpeaking();
client_->OnNSViewStopSpeaking();
}
- (void)cancelComposition {
......
......@@ -278,6 +278,8 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
// RenderWidgetHostNSViewClient implementation.
RenderWidgetHostViewMac* GetRenderWidgetHostViewMac() override;
BrowserAccessibilityManager* GetRootBrowserAccessibilityManager() override;
void OnNSViewSyncIsRenderViewHost(bool* is_render_view) override;
void OnNSViewRequestShutdown() override;
void OnNSViewIsFirstResponderChanged(bool is_first_responder) override;
void OnNSViewWindowIsKeyChanged(bool is_key) override;
......@@ -321,6 +323,9 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
void OnNSViewPaste() override;
void OnNSViewPasteAndMatchStyle() override;
void OnNSViewSelectAll() override;
void OnNSViewSpeakSelection() override;
void OnNSViewStopSpeaking() override;
void OnNSViewSyncIsSpeaking(bool* is_speaking) override;
// BrowserCompositorMacClient implementation.
SkColor BrowserCompositorMacGetGutterColor() const override;
......
......@@ -1229,6 +1229,16 @@ RenderWidgetHostViewMac* RenderWidgetHostViewMac::GetRenderWidgetHostViewMac() {
return this;
}
BrowserAccessibilityManager*
RenderWidgetHostViewMac::GetRootBrowserAccessibilityManager() {
return host()->GetRootBrowserAccessibilityManager();
}
void RenderWidgetHostViewMac::OnNSViewSyncIsRenderViewHost(
bool* is_render_view) {
*is_render_view = RenderViewHost::From(host()) != nullptr;
}
void RenderWidgetHostViewMac::OnNSViewRequestShutdown() {
if (!weak_factory_.HasWeakPtrs()) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
......@@ -1563,6 +1573,31 @@ void RenderWidgetHostViewMac::OnNSViewSelectAll() {
}
}
void RenderWidgetHostViewMac::OnNSViewSyncIsSpeaking(bool* is_speaking) {
*is_speaking = ui::TextServicesContextMenu::IsSpeaking();
}
void RenderWidgetHostViewMac::OnNSViewSpeakSelection() {
RenderWidgetHostView* target = this;
WebContents* web_contents = GetWebContents();
if (web_contents) {
content::BrowserPluginGuestManager* guest_manager =
web_contents->GetBrowserContext()->GetGuestManager();
if (guest_manager) {
content::WebContents* guest =
guest_manager->GetFullPageGuest(web_contents);
if (guest) {
target = guest->GetRenderWidgetHostView();
}
}
}
target->SpeakSelection();
}
void RenderWidgetHostViewMac::OnNSViewStopSpeaking() {
ui::TextServicesContextMenu::StopSpeaking();
}
void RenderWidgetHostViewMac::OnGotStringForDictionaryOverlay(
int32_t target_widget_process_id,
int32_t target_widget_routing_id,
......
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