1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_BASE_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_BASE_H_ 7 8 #include <stddef.h> 9 #include <stdint.h> 10 11 #include <memory> 12 #include <vector> 13 14 #include "base/callback_forward.h" 15 #include "base/i18n/rtl.h" 16 #include "base/macros.h" 17 #include "base/observer_list.h" 18 #include "base/optional.h" 19 #include "base/process/kill.h" 20 #include "base/strings/string16.h" 21 #include "base/time/time.h" 22 #include "build/build_config.h" 23 #include "components/viz/common/surfaces/scoped_surface_id_allocator.h" 24 #include "components/viz/common/surfaces/surface_id.h" 25 #include "components/viz/host/hit_test/hit_test_query.h" 26 #include "content/browser/renderer_host/display_feature.h" 27 #include "content/browser/renderer_host/event_with_latency_info.h" 28 #include "content/common/content_export.h" 29 #include "content/public/browser/render_frame_metadata_provider.h" 30 #include "content/public/browser/render_widget_host_view.h" 31 #include "content/public/common/widget_type.h" 32 #include "services/viz/public/mojom/hit_test/hit_test_region_list.mojom.h" 33 #include "third_party/blink/public/common/page/content_to_visible_time_reporter.h" 34 #include "third_party/blink/public/mojom/frame/intrinsic_sizing_info.mojom-forward.h" 35 #include "third_party/blink/public/mojom/input/input_event_result.mojom-shared.h" 36 #include "third_party/blink/public/mojom/page/record_content_to_visible_time_request.mojom-forward.h" 37 #include "third_party/skia/include/core/SkImageInfo.h" 38 #include "ui/accessibility/ax_tree_id_registry.h" 39 #include "ui/base/ime/mojom/text_input_state.mojom-forward.h" 40 #include "ui/base/ime/text_input_mode.h" 41 #include "ui/base/ime/text_input_type.h" 42 #include "ui/display/display.h" 43 #include "ui/events/event_constants.h" 44 #include "ui/gfx/geometry/rect.h" 45 #include "ui/gfx/native_widget_types.h" 46 #include "ui/gfx/range/range.h" 47 #include "ui/surface/transport_dib.h" 48 49 namespace blink { 50 class WebMouseEvent; 51 class WebMouseWheelEvent; 52 } 53 54 namespace ui { 55 enum class DomCode; 56 class LatencyInfo; 57 class TouchEvent; 58 struct DidOverscrollParams; 59 } 60 61 namespace content { 62 63 class BrowserAccessibilityDelegate; 64 class BrowserAccessibilityManager; 65 class CursorManager; 66 class MouseWheelPhaseHandler; 67 class RenderWidgetHostImpl; 68 class RenderWidgetHostViewBaseObserver; 69 class SyntheticGestureTarget; 70 class TextInputManager; 71 class TouchSelectionControllerClientManager; 72 class WebCursor; 73 class DelegatedFrameHost; 74 75 // Basic implementation shared by concrete RenderWidgetHostView subclasses. 76 class CONTENT_EXPORT RenderWidgetHostViewBase : public RenderWidgetHostView { 77 public: current_device_scale_factor()78 float current_device_scale_factor() const { 79 return current_device_scale_factor_; 80 } 81 82 // Returns the focused RenderWidgetHost inside this |view|'s RWH. 83 RenderWidgetHostImpl* GetFocusedWidget() const; 84 85 // RenderWidgetHostView implementation. 86 RenderWidgetHost* GetRenderWidgetHost() final; 87 ui::TextInputClient* GetTextInputClient() override; WasUnOccluded()88 void WasUnOccluded() override {} WasOccluded()89 void WasOccluded() override {} 90 void SetIsInVR(bool is_in_vr) override; 91 base::string16 GetSelectedText() override; 92 bool IsMouseLocked() override; 93 bool GetIsMouseLockedUnadjustedMovementForTesting() override; 94 bool LockKeyboard(base::Optional<base::flat_set<ui::DomCode>> codes) override; 95 void SetBackgroundColor(SkColor color) override; 96 base::Optional<SkColor> GetBackgroundColor() override; 97 void UnlockKeyboard() override; 98 bool IsKeyboardLocked() override; 99 base::flat_map<std::string, std::string> GetKeyboardLayoutMap() override; 100 gfx::Size GetVisibleViewportSize() override; 101 void SetInsets(const gfx::Insets& insets) override; 102 bool IsSurfaceAvailableForCopy() override; 103 void CopyFromSurface( 104 const gfx::Rect& src_rect, 105 const gfx::Size& output_size, 106 base::OnceCallback<void(const SkBitmap&)> callback) override; 107 std::unique_ptr<viz::ClientFrameSinkVideoCapturer> CreateVideoCapturer() 108 override; 109 void GetScreenInfo(blink::ScreenInfo* screen_info) override; 110 void EnableAutoResize(const gfx::Size& min_size, 111 const gfx::Size& max_size) override; 112 void DisableAutoResize(const gfx::Size& new_size) override; 113 float GetDeviceScaleFactor() final; 114 TouchSelectionControllerClientManager* 115 GetTouchSelectionControllerClientManager() override; 116 void SetRecordContentToVisibleTimeRequest( 117 base::TimeTicks start_time, 118 bool destination_is_loaded, 119 bool show_reason_tab_switching, 120 bool show_reason_unoccluded, 121 bool show_reason_bfcache_restore) final; 122 123 // This only needs to be overridden by RenderWidgetHostViewBase subclasses 124 // that handle content embedded within other RenderWidgetHostViews. 125 gfx::PointF TransformPointToRootCoordSpaceF( 126 const gfx::PointF& point) override; 127 gfx::PointF TransformRootPointToViewCoordSpace( 128 const gfx::PointF& point) override; 129 130 virtual void UpdateIntrinsicSizingInfo( 131 blink::mojom::IntrinsicSizingInfoPtr sizing_info); 132 133 static void CopyMainAndPopupFromSurface( 134 base::WeakPtr<RenderWidgetHostImpl> main_host, 135 base::WeakPtr<DelegatedFrameHost> main_frame_host, 136 base::WeakPtr<RenderWidgetHostImpl> popup_host, 137 base::WeakPtr<DelegatedFrameHost> popup_frame_host, 138 const gfx::Rect& src_subrect, 139 const gfx::Size& dst_size, 140 float scale_factor, 141 base::OnceCallback<void(const SkBitmap&)> callback); 142 143 void SetWidgetType(WidgetType widget_type); 144 145 WidgetType GetWidgetType(); 146 147 // Notification that a resize or move session ended on the native widget. 148 void UpdateScreenInfo(gfx::NativeView view); 149 150 // Tells if the display property (work area/scale factor) has 151 // changed since the last time. 152 bool HasDisplayPropertyChanged(gfx::NativeView view); 153 154 // Called by the TextInputManager to notify the view about being removed from 155 // the list of registered views, i.e., TextInputManager is no longer tracking 156 // TextInputState from this view. The RWHV should reset |text_input_manager_| 157 // to nullptr. 158 void DidUnregisterFromTextInputManager(TextInputManager* text_input_manager); 159 160 // Informs the view that the renderer's visual properties have been updated 161 // and a new viz::LocalSurfaceId has been allocated. 162 virtual viz::ScopedSurfaceIdAllocator DidUpdateVisualProperties( 163 const cc::RenderFrameMetadata& metadata); 164 165 // Returns the time set by SetLastRecordContentToVisibleTimeRequest. If this 166 // was not preceded by a call to SetLastRecordContentToVisibleTimeRequest the 167 // |event_start_time| field of the returned struct will have a null 168 // timestamp. Calling this will reset |last_record_tab_switch_time_request_| 169 // to null. 170 blink::mojom::RecordContentToVisibleTimeRequestPtr 171 TakeRecordContentToVisibleTimeRequest(); 172 173 base::WeakPtr<RenderWidgetHostViewBase> GetWeakPtr(); 174 175 //---------------------------------------------------------------------------- 176 // The following methods can be overridden by derived classes. 177 178 // Returns the root-view associated with this view. Always returns |this| for 179 // non-embeddable derived views. 180 virtual RenderWidgetHostViewBase* GetRootView(); 181 182 // Notifies the View that the renderer text selection has changed. 183 virtual void SelectionChanged(const base::string16& text, 184 size_t offset, 185 const gfx::Range& range); 186 187 // The requested size of the renderer. May differ from GetViewBounds().size() 188 // when the view requires additional throttling. 189 virtual gfx::Size GetRequestedRendererSize(); 190 191 // Returns the current capture sequence number. 192 virtual uint32_t GetCaptureSequenceNumber() const; 193 194 // The size of the view's backing surface in non-DPI-adjusted pixels. 195 virtual gfx::Size GetCompositorViewportPixelSize(); 196 197 // If mouse wheels can only specify the number of ticks of some static 198 // multiplier constant, this method returns that constant (in DIPs). If mouse 199 // wheels can specify an arbitrary delta this returns 0. 200 virtual int GetMouseWheelMinimumGranularity() const; 201 202 // Called prior to forwarding input event messages to the renderer, giving 203 // the view a chance to perform in-process event filtering or processing. 204 // Return values of |NOT_CONSUMED| or |UNKNOWN| will result in |input_event| 205 // being forwarded. 206 virtual blink::mojom::InputEventResultState FilterInputEvent( 207 const blink::WebInputEvent& input_event); 208 209 virtual void WheelEventAck(const blink::WebMouseWheelEvent& event, 210 blink::mojom::InputEventResultState ack_result); 211 212 virtual void GestureEventAck(const blink::WebGestureEvent& event, 213 blink::mojom::InputEventResultState ack_result); 214 215 virtual void ChildDidAckGestureEvent( 216 const blink::WebGestureEvent& event, 217 blink::mojom::InputEventResultState ack_result); 218 219 // Create a platform specific SyntheticGestureTarget implementation that will 220 // be used to inject synthetic input events. 221 virtual std::unique_ptr<SyntheticGestureTarget> 222 CreateSyntheticGestureTarget() = 0; 223 224 // Create a BrowserAccessibilityManager for a frame in this view. 225 // If |for_root_frame| is true, creates a BrowserAccessibilityManager 226 // suitable for the root frame, which may be linked to its native 227 // window container. 228 virtual BrowserAccessibilityManager* CreateBrowserAccessibilityManager( 229 BrowserAccessibilityDelegate* delegate, 230 bool for_root_frame); 231 232 virtual gfx::AcceleratedWidget AccessibilityGetAcceleratedWidget(); 233 virtual gfx::NativeViewAccessible AccessibilityGetNativeViewAccessible(); 234 virtual gfx::NativeViewAccessible 235 AccessibilityGetNativeViewAccessibleForWindow(); SetMainFrameAXTreeID(ui::AXTreeID id)236 virtual void SetMainFrameAXTreeID(ui::AXTreeID id) {} 237 // Informs that the focused DOM node has changed. FocusedNodeChanged(bool is_editable_node,const gfx::Rect & node_bounds_in_screen)238 virtual void FocusedNodeChanged(bool is_editable_node, 239 const gfx::Rect& node_bounds_in_screen) {} 240 241 // This method will reset the fallback to the first surface after navigation. 242 virtual void ResetFallbackToFirstNavigationSurface() = 0; 243 244 // Requests a new CompositorFrame from the renderer. This is done by 245 // allocating a new viz::LocalSurfaceId which forces a commit and draw. 246 virtual bool RequestRepaintForTesting(); 247 248 // Because the associated remote WebKit instance can asynchronously 249 // prevent-default on a dispatched touch event, the touch events are queued in 250 // the GestureRecognizer until invocation of ProcessAckedTouchEvent releases 251 // it to be consumed (when |ack_result| is NOT_CONSUMED OR NO_CONSUMER_EXISTS) 252 // or ignored (when |ack_result| is CONSUMED). 253 // |touch|'s coordinates are in the coordinate space of the view to which it 254 // was targeted. 255 virtual void ProcessAckedTouchEvent( 256 const TouchEventWithLatencyInfo& touch, 257 blink::mojom::InputEventResultState ack_result); 258 DidOverscroll(const ui::DidOverscrollParams & params)259 virtual void DidOverscroll(const ui::DidOverscrollParams& params) {} 260 DidStopFlinging()261 virtual void DidStopFlinging() {} 262 263 // Returns the ID associated with the CompositorFrameSink of this view. 264 virtual const viz::FrameSinkId& GetFrameSinkId() const = 0; 265 266 // Returns the LocalSurfaceId allocated by the parent client for this view. 267 virtual const viz::LocalSurfaceId& GetLocalSurfaceId() const = 0; 268 269 // Called whenever the browser receives updated hit test data from viz. NotifyHitTestRegionUpdated(const viz::AggregatedHitTestRegion & region)270 virtual void NotifyHitTestRegionUpdated( 271 const viz::AggregatedHitTestRegion& region) {} 272 273 // Indicates whether the widget has resized or moved within its embedding 274 // page during the 500 milliseconds prior to the event. 275 virtual bool ScreenRectIsUnstableFor(const blink::WebInputEvent& event); 276 PreProcessMouseEvent(const blink::WebMouseEvent & event)277 virtual void PreProcessMouseEvent(const blink::WebMouseEvent& event) {} PreProcessTouchEvent(const blink::WebTouchEvent & event)278 virtual void PreProcessTouchEvent(const blink::WebTouchEvent& event) {} 279 280 void ProcessMouseEvent(const blink::WebMouseEvent& event, 281 const ui::LatencyInfo& latency); 282 void ProcessMouseWheelEvent(const blink::WebMouseWheelEvent& event, 283 const ui::LatencyInfo& latency); 284 void ProcessTouchEvent(const blink::WebTouchEvent& event, 285 const ui::LatencyInfo& latency); 286 virtual void ProcessGestureEvent(const blink::WebGestureEvent& event, 287 const ui::LatencyInfo& latency); 288 289 // Transform a point that is in the coordinate space of a Surface that is 290 // embedded within the RenderWidgetHostViewBase's Surface to the 291 // coordinate space of an embedding, or embedded, Surface. Typically this 292 // means that a point was received from an out-of-process iframe's 293 // RenderWidget and needs to be translated to viewport coordinates for the 294 // root RWHV, in which case this method is called on the root RWHV with the 295 // out-of-process iframe's SurfaceId. 296 // Returns false when this attempts to transform a point between coordinate 297 // spaces of surfaces where one does not contain the other. To transform 298 // between sibling surfaces, the point must be transformed to the root's 299 // coordinate space as an intermediate step. 300 bool TransformPointToLocalCoordSpace(const gfx::PointF& point, 301 const viz::SurfaceId& original_surface, 302 gfx::PointF* transformed_point); 303 304 // Given a RenderWidgetHostViewBase that renders to a Surface that is 305 // contained within this class' Surface, find the relative transform between 306 // the Surfaces and apply it to a point. Returns false if a Surface has not 307 // yet been created or if |target_view| is not a descendant RWHV from our 308 // client. 309 virtual bool TransformPointToCoordSpaceForView( 310 const gfx::PointF& point, 311 RenderWidgetHostViewBase* target_view, 312 gfx::PointF* transformed_point); 313 314 // On success, returns true and modifies |*transform| to represent the 315 // transformation mapping a point in the coordinate space of this view 316 // into the coordinate space of the target view. 317 // On Failure, returns false, and leaves |*transform| unchanged. 318 // This function will fail if viz hit testing is not enabled, or if either 319 // this view or the target view has no current FrameSinkId. The latter may 320 // happen if either view is not currently visible in the viewport. 321 // This function is useful if there are multiple points to transform between 322 // the same two views. |target_view| must be non-null. 323 bool GetTransformToViewCoordSpace(RenderWidgetHostViewBase* target_view, 324 gfx::Transform* transform); 325 326 // Subclass identifier for RenderWidgetHostViewChildFrames. This is useful 327 // to be able to know if this RWHV is embedded within another RWHV. If 328 // other kinds of embeddable RWHVs are created, this should be renamed to 329 // a more generic term -- in which case, static casts to RWHVChildFrame will 330 // need to also be resolved. 331 virtual bool IsRenderWidgetHostViewChildFrame(); 332 333 // Notify the View that a screen rect update is being sent to the 334 // RenderWidget. Related platform-specific updates can be sent from here. WillSendScreenRects()335 virtual void WillSendScreenRects() {} 336 337 // Returns true if the current view is in virtual reality mode. 338 virtual bool IsInVR() const; 339 340 // Obtains the root window FrameSinkId. 341 virtual viz::FrameSinkId GetRootFrameSinkId(); 342 343 // Returns the SurfaceId currently in use by the renderer to submit compositor 344 // frames. 345 virtual viz::SurfaceId GetCurrentSurfaceId() const = 0; 346 347 // Returns true if this view's size have been initialized. 348 virtual bool HasSize() const; 349 350 // Informs the view that the assocaited InterstitialPage was attached. OnInterstitialPageAttached()351 virtual void OnInterstitialPageAttached() {} 352 353 // Tells the view that the assocaited InterstitialPage will going away (but is 354 // not yet destroyed, as InterstitialPage destruction is asynchronous). The 355 // view may use this notification to clean up associated resources. This 356 // should be called before the WebContents is fully destroyed. OnInterstitialPageGoingAway()357 virtual void OnInterstitialPageGoingAway() {} 358 359 // Returns true if the visual properties should be sent to the renderer at 360 // this time. This function is intended for subclasses to suppress 361 // synchronization, the default implementation returns true. 362 virtual bool CanSynchronizeVisualProperties(); 363 364 // Extracts information about any active pointers and cancels any existing 365 // active pointers by dispatching synthetic cancel events. 366 virtual std::vector<std::unique_ptr<ui::TouchEvent>> 367 ExtractAndCancelActiveTouches(); 368 369 // Used to transfer pointer state from one view to another. It recreates the 370 // pointer state by dispatching touch down events. TransferTouches(const std::vector<std::unique_ptr<ui::TouchEvent>> & touches)371 virtual void TransferTouches( 372 const std::vector<std::unique_ptr<ui::TouchEvent>>& touches) {} 373 SetLastPointerType(ui::EventPointerType last_pointer_type)374 virtual void SetLastPointerType(ui::EventPointerType last_pointer_type) {} 375 376 //---------------------------------------------------------------------------- 377 // The following methods are related to IME. 378 // TODO(ekaramad): Most of the IME methods should not stay virtual after IME 379 // is implemented for OOPIF. After fixing IME, mark the corresponding methods 380 // non-virtual (https://crbug.com/578168). 381 382 // Updates the state of the input method attached to the view. 383 virtual void TextInputStateChanged( 384 const ui::mojom::TextInputState& text_input_state); 385 386 // Cancel the ongoing composition of the input method attached to the view. 387 virtual void ImeCancelComposition(); 388 389 // Notifies the view that the renderer selection bounds has changed. 390 // Selection bounds are described as a focus bound which is the current 391 // position of caret on the screen, as well as the anchor bound which is the 392 // starting position of the selection. The coordinates are with respect to 393 // RenderWidget's window's origin. Focus and anchor bound are represented as 394 // gfx::Rect. 395 virtual void SelectionBoundsChanged(const gfx::Rect& anchor_rect, 396 base::i18n::TextDirection anchor_dir, 397 const gfx::Rect& focus_rect, 398 base::i18n::TextDirection focus_dir, 399 bool is_anchor_first); 400 401 // Updates the range of the marked text in an IME composition. 402 virtual void ImeCompositionRangeChanged( 403 const gfx::Range& range, 404 const std::vector<gfx::Rect>& character_bounds); 405 406 //---------------------------------------------------------------------------- 407 // The following pure virtual methods are implemented by derived classes. 408 409 // Perform all the initialization steps necessary for this object to represent 410 // a popup (such as a <select> dropdown), then shows the popup at |pos|. 411 virtual void InitAsPopup(RenderWidgetHostView* parent_host_view, 412 const gfx::Rect& bounds) = 0; 413 414 // Perform all the initialization steps necessary for this object to represent 415 // a full screen window. 416 // |reference_host_view| is the view associated with the creating page that 417 // helps to position the full screen widget on the correct monitor. 418 virtual void InitAsFullscreen(RenderWidgetHostView* reference_host_view) = 0; 419 420 // Sets the cursor for this view to the one associated with the specified 421 // cursor_type. 422 virtual void UpdateCursor(const WebCursor& cursor) = 0; 423 424 // Changes the cursor that is displayed on screen. This may or may not match 425 // the current cursor's view which was set by UpdateCursor. 426 virtual void DisplayCursor(const WebCursor& cursor); 427 428 // Views that manage cursors for window return a CursorManager. Other views 429 // return nullptr. 430 virtual CursorManager* GetCursorManager(); 431 432 // Indicates whether the page has finished loading. 433 virtual void SetIsLoading(bool is_loading) = 0; 434 435 // Notifies the View that the renderer has ceased to exist. 436 virtual void RenderProcessGone() = 0; 437 438 // Tells the View to destroy itself. 439 virtual void Destroy(); 440 441 // Tells the View that the tooltip text for the current mouse position over 442 // the page has changed. 443 virtual void SetTooltipText(const base::string16& tooltip_text) = 0; 444 445 // Displays the requested tooltip on the screen. DisplayTooltipText(const base::string16 & tooltip_text)446 virtual void DisplayTooltipText(const base::string16& tooltip_text) {} 447 448 // Transforms |point| to be in the coordinate space of browser compositor's 449 // surface. This is in DIP. 450 virtual void TransformPointToRootSurface(gfx::PointF* point); 451 452 // Gets the bounds of the top-level window, in screen coordinates. 453 virtual gfx::Rect GetBoundsInRootWindow() = 0; 454 455 // Called by the WebContentsImpl when a user tries to navigate a new page on 456 // main frame. 457 virtual void OnDidNavigateMainFrameToNewPage(); 458 459 // Called by WebContentsImpl to notify the view about a change in visibility 460 // of context menu. The view can then perform platform specific tasks and 461 // changes. SetShowingContextMenu(bool showing)462 virtual void SetShowingContextMenu(bool showing) {} 463 464 virtual void OnAutoscrollStart(); 465 466 // Gets the DisplayFeature whose offset and mask_length are expressed in DIPs 467 // relative to the view. See display_feature.h for more details. 468 virtual base::Optional<DisplayFeature> GetDisplayFeature() = 0; 469 470 virtual void SetDisplayFeatureForTesting( 471 const DisplayFeature* display_feature) = 0; 472 473 // Returns the associated RenderWidgetHostImpl. host()474 RenderWidgetHostImpl* host() const { return host_; } 475 476 // Process swap messages sent before |frame_token| in RenderWidgetHostImpl. 477 void OnFrameTokenChangedForView(uint32_t frame_token); 478 479 // Add and remove observers for lifetime event notifications. The order in 480 // which notifications are sent to observers is undefined. Clients must be 481 // sure to remove the observer before they go away. 482 void AddObserver(RenderWidgetHostViewBaseObserver* observer); 483 void RemoveObserver(RenderWidgetHostViewBaseObserver* observer); 484 485 // Returns a reference to the current instance of TextInputManager. The 486 // reference is obtained from RenderWidgetHostDelegate. The first time a non- 487 // null reference is obtained, its value is cached in |text_input_manager_| 488 // and this view is registered with it. The RWHV will unregister from the 489 // TextInputManager if it is destroyed or if the TextInputManager itself is 490 // destroyed. The unregistration of the RWHV from TextInputManager is 491 // necessary and must be done by explicitly calling 492 // TextInputManager::Unregister. 493 // It is safer to use this method rather than directly dereferencing 494 // |text_input_manager_|. 495 TextInputManager* GetTextInputManager(); 496 497 void StopFling(); 498 is_fullscreen()499 bool is_fullscreen() { return is_fullscreen_; } 500 set_is_currently_scrolling_viewport(bool is_currently_scrolling_viewport)501 void set_is_currently_scrolling_viewport( 502 bool is_currently_scrolling_viewport) { 503 is_currently_scrolling_viewport_ = is_currently_scrolling_viewport; 504 } 505 is_currently_scrolling_viewport()506 bool is_currently_scrolling_viewport() { 507 return is_currently_scrolling_viewport_; 508 } 509 510 virtual void DidNavigate(); 511 512 // Called when the RenderWidgetHostImpl has be initialized. OnRenderWidgetInit()513 virtual void OnRenderWidgetInit() {} 514 set_is_evicted()515 void set_is_evicted() { is_evicted_ = true; } reset_is_evicted()516 void reset_is_evicted() { is_evicted_ = false; } is_evicted()517 bool is_evicted() { return is_evicted_; } 518 519 // SetContentBackgroundColor is called when the renderer wants to update the 520 // view's background color. 521 void SetContentBackgroundColor(SkColor color); content_background_color()522 base::Optional<SkColor> content_background_color() const { 523 return content_background_color_; 524 } 525 526 protected: 527 explicit RenderWidgetHostViewBase(RenderWidgetHost* host); 528 529 void NotifyObserversAboutShutdown(); 530 531 virtual MouseWheelPhaseHandler* GetMouseWheelPhaseHandler(); 532 533 // Applies background color without notifying the RenderWidget about 534 // opaqueness changes. This allows us to, when navigating to a new page, 535 // transfer this color to that page. This allows us to pass this background 536 // color to new views on navigation. 537 virtual void UpdateBackgroundColor() = 0; 538 539 // Stops flinging if a GSU event with momentum phase is sent to the renderer 540 // but not consumed. 541 virtual void StopFlingingIfNecessary( 542 const blink::WebGestureEvent& event, 543 blink::mojom::InputEventResultState ack_result); 544 545 // If |event| is a touchpad pinch or double tap event for which we've sent a 546 // synthetic wheel event, forward the |event| to the renderer, subject to 547 // |ack_result| which is the ACK result of the synthetic wheel. 548 virtual void ForwardTouchpadZoomEventIfNecessary( 549 const blink::WebGestureEvent& event, 550 blink::mojom::InputEventResultState ack_result); 551 552 virtual bool HasFallbackSurface() const; 553 554 // The model object. Access is protected to allow access to 555 // RenderWidgetHostViewChildFrame. 556 RenderWidgetHostImpl* host_; 557 558 // Is this a fullscreen view? 559 bool is_fullscreen_ = false; 560 561 // Whether this view is a frame or a popup. 562 WidgetType widget_type_ = WidgetType::kFrame; 563 564 // Indicates whether keyboard lock is active for this view. 565 bool keyboard_locked_ = false; 566 567 // Indicates whether the scroll offset of the root layer is at top, i.e., 568 // whether scroll_offset.y() == 0. 569 bool is_scroll_offset_at_top_ = true; 570 571 // The scale factor of the display the renderer is currently on. 572 float current_device_scale_factor_ = 0; 573 574 // The color space of the display the renderer is currently on. 575 gfx::DisplayColorSpaces current_display_color_spaces_; 576 577 // The orientation of the display the renderer is currently on. 578 display::Display::Rotation current_display_rotation_ = 579 display::Display::ROTATE_0; 580 581 // A reference to current TextInputManager instance this RWHV is registered 582 // with. This is initially nullptr until the first time the view calls 583 // GetTextInputManager(). It also becomes nullptr when TextInputManager is 584 // destroyed before the RWHV is destroyed. 585 TextInputManager* text_input_manager_ = nullptr; 586 587 // The background color used in the current renderer. 588 base::Optional<SkColor> content_background_color_; 589 590 // The default background color used before getting the 591 // |content_background_color|. 592 base::Optional<SkColor> default_background_color_; 593 594 bool is_currently_scrolling_viewport_ = false; 595 596 protected: 597 ~RenderWidgetHostViewBase() override; 598 599 private: 600 FRIEND_TEST_ALL_PREFIXES( 601 BrowserSideFlingBrowserTest, 602 EarlyTouchscreenFlingCancelationOnInertialGSUAckNotConsumed); 603 FRIEND_TEST_ALL_PREFIXES( 604 BrowserSideFlingBrowserTest, 605 EarlyTouchpadFlingCancelationOnInertialGSUAckNotConsumed); 606 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostDelegatedInkMetadataTest, 607 FlagGetsSetFromRenderFrameMetadata); 608 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostInputEventRouterTest, 609 QueryResultAfterChildViewDead); 610 FRIEND_TEST_ALL_PREFIXES(DelegatedInkPointTest, EventForwardedToCompositor); 611 FRIEND_TEST_ALL_PREFIXES(DelegatedInkPointTest, 612 MojoInterfaceReboundOnDisconnect); 613 614 void SynchronizeVisualProperties(); 615 616 // Called when display properties that need to be synchronized with the 617 // renderer process changes. This method is called before notifying 618 // RenderWidgetHostImpl in order to allow the view to allocate a new 619 // LocalSurfaceId. OnSynchronizedDisplayPropertiesChanged()620 virtual void OnSynchronizedDisplayPropertiesChanged() {} 621 622 // Transforms |point| from |original_view| coord space to |target_view| coord 623 // space. Result is stored in |transformed_point|. Returns true if the 624 // transform is successful, false otherwise. 625 bool TransformPointToTargetCoordSpace(RenderWidgetHostViewBase* original_view, 626 RenderWidgetHostViewBase* target_view, 627 const gfx::PointF& point, 628 gfx::PointF* transformed_point) const; 629 view_stopped_flinging_for_test()630 bool view_stopped_flinging_for_test() const { 631 return view_stopped_flinging_for_test_; 632 } 633 634 gfx::Rect current_display_area_; 635 636 base::ObserverList<RenderWidgetHostViewBaseObserver>::Unchecked observers_; 637 638 base::Optional<blink::WebGestureEvent> pending_touchpad_pinch_begin_; 639 640 // The last tab switch processing start request. This should only be set and 641 // retrieved using SetRecordContentToVisibleTimeRequest and 642 // TakeRecordContentToVisibleTimeRequest. 643 blink::mojom::RecordContentToVisibleTimeRequestPtr 644 last_record_tab_switch_time_request_; 645 646 // True when StopFlingingIfNecessary() calls StopFling(). 647 bool view_stopped_flinging_for_test_ = false; 648 649 bool is_evicted_ = false; 650 651 base::WeakPtrFactory<RenderWidgetHostViewBase> weak_factory_{this}; 652 653 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewBase); 654 }; 655 656 } // namespace content 657 658 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_BASE_H_ 659