Chromium Code Reviews| Index: content/browser/web_contents/web_contents_impl.cc |
| diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc |
| index 35f0efe14baa41d92a29d23291e5b71ab2ab4d67..2fdd56da5e705ad04b7d55a7bcb5b837fb3699af 100644 |
| --- a/content/browser/web_contents/web_contents_impl.cc |
| +++ b/content/browser/web_contents/web_contents_impl.cc |
| @@ -94,6 +94,7 @@ |
| #include "content/public/browser/content_browser_client.h" |
| #include "content/public/browser/download_manager.h" |
| #include "content/public/browser/download_url_parameters.h" |
| +#include "content/public/browser/focused_node_details.h" |
| #include "content/public/browser/guest_mode.h" |
| #include "content/public/browser/invalidate_type.h" |
| #include "content/public/browser/javascript_dialog_manager.h" |
| @@ -139,6 +140,11 @@ |
| #include "ui/events/blink/web_input_event_traits.h" |
| #include "ui/gl/gl_switches.h" |
| +#if defined(OS_WIN) |
| +#include "content/browser/renderer_host/dip_util.h" |
| +#include "ui/gfx/geometry/dip_util.h" |
| +#endif |
| + |
| #if defined(OS_ANDROID) |
| #include "content/browser/android/content_video_view.h" |
| #include "content/browser/android/date_time_chooser_android.h" |
| @@ -4190,6 +4196,16 @@ bool WebContentsImpl::HideDownloadUI() const { |
| return is_overlay_content_; |
| } |
| +bool WebContentsImpl::IsFocusedElementEditable() { |
| + RenderFrameHostImpl* frame = GetFocusedFrame(); |
| + return frame && frame->has_focused_editable_element(); |
| +} |
| + |
| +void WebContentsImpl::ClearFocusedElement() { |
| + if (auto* frame = GetFocusedFrame()) |
| + frame->ClearFocusedElement(); |
| +} |
| + |
| bool WebContentsImpl::IsNeverVisible() { |
| if (!delegate_) |
| return false; |
| @@ -4695,6 +4711,35 @@ void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node, |
| frame_tree_.SetFocusedFrame(node, source); |
| } |
| +void WebContentsImpl::OnFocusedElementChangedInFrame( |
| + RenderFrameHostImpl* frame, |
| + const gfx::Rect& bounds_in_root_view) { |
| + RenderWidgetHostViewBase* root_view = |
| + static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView()); |
| + if (!root_view || !frame->GetView()) |
| + return; |
| + |
| + // Converting to screen coordinates. |
| + gfx::Point origin = bounds_in_root_view.origin(); |
| + origin += root_view->GetViewBounds().OffsetFromOrigin(); |
| + gfx::Rect bounds_in_screen(origin, bounds_in_root_view.size()); |
| + |
| + // TODO(ekaramad): Do we want to early return here when |frame| is not focused |
| + // and the focused frame has active editable element? |
| + root_view->FocusedNodeChanged(frame->has_focused_editable_element(), |
| + bounds_in_screen); |
| + |
| + FocusedNodeDetails details = {frame->has_focused_editable_element(), |
| + bounds_in_screen}; |
| + |
| + // TODO(ekaramad): Should we do this step with |this| as source now? Requires |
| + // changes to public API. |
|
ncarter (slow)
2016/12/16 19:17:21
WebContents can be made to be the source (and, I t
EhsanK
2016/12/20 16:39:11
Yes I am not quite fond of notifications as they c
ncarter (slow)
2016/12/20 22:37:44
SGTM!
|
| + NotificationService::current()->Notify( |
| + NOTIFICATION_FOCUS_CHANGED_IN_PAGE, |
| + Source<RenderViewHost>(GetRenderViewHost()), |
| + Details<FocusedNodeDetails>(&details)); |
| +} |
| + |
| bool WebContentsImpl::DidAddMessageToConsole(int32_t level, |
| const base::string16& message, |
| int32_t line_no, |
| @@ -5300,6 +5345,21 @@ bool WebContentsImpl::AddDomainInfoToRapporSample(rappor::Sample* sample) { |
| return true; |
| } |
| +void WebContentsImpl::FocusedNodeTouched(bool editable) { |
| +#if defined(OS_WIN) |
| + // We use the cursor position to determine where the touch occurred. |
| + RenderWidgetHostView* view = GetRenderWidgetHostView(); |
| + if (!view) |
| + return; |
| + POINT cursor_pos = {}; |
| + ::GetCursorPos(&cursor_pos); |
| + float scale = GetScaleFactorForView(view); |
| + gfx::Point location_dips_screen = |
| + gfx::ConvertPointToDIP(scale, gfx::Point(cursor_pos)); |
| + view->FocusedNodeTouched(location_dips_screen, editable); |
| +#endif |
| +} |
| + |
| void WebContentsImpl::ShowInsecureLocalhostWarningIfNeeded() { |
| bool allow_localhost = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| switches::kAllowInsecureLocalhost); |