summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/frame/web_frame_widget_impl.h
blob: cec066aad5dc5a98e462df0a58788d088cf90974 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
/*
 * Copyright (C) 2014 Google Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *     * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following disclaimer
 * in the documentation and/or other materials provided with the
 * distribution.
 *     * Neither the name of Google Inc. nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_WEB_FRAME_WIDGET_IMPL_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_WEB_FRAME_WIDGET_IMPL_H_

#include "base/memory/weak_ptr.h"
#include "base/single_thread_task_runner.h"
#include "base/types/pass_key.h"
#include "build/build_config.h"
#include "cc/input/event_listener_properties.h"
#include "cc/input/layer_selection_bound.h"
#include "cc/input/overscroll_behavior.h"
#include "cc/trees/layer_tree_host.h"
#include "services/viz/public/mojom/hit_test/input_target_client.mojom-blink.h"
#include "third_party/blink/public/common/input/web_coalesced_input_event.h"
#include "third_party/blink/public/common/input/web_gesture_device.h"
#include "third_party/blink/public/mojom/input/input_handler.mojom-blink.h"
#include "third_party/blink/public/mojom/manifest/display_mode.mojom-blink.h"
#include "third_party/blink/public/mojom/page/drag.mojom-blink.h"
#include "third_party/blink/public/mojom/page/widget.mojom-blink.h"
#include "third_party/blink/public/mojom/scroll/scroll_into_view_params.mojom-blink-forward.h"
#include "third_party/blink/public/platform/cross_variant_mojo_util.h"
#include "third_party/blink/public/platform/web_drag_data.h"
#include "third_party/blink/public/web/web_frame_widget.h"
#include "third_party/blink/public/web/web_meaningful_layout.h"
#include "third_party/blink/renderer/core/clipboard/data_object.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/exported/web_page_popup_impl.h"
#include "third_party/blink/renderer/core/frame/web_local_frame_impl.h"
#include "third_party/blink/renderer/core/html/battery_savings.h"
#include "third_party/blink/renderer/core/page/event_with_hit_test_results.h"
#include "third_party/blink/renderer/core/page/page_widget_delegate.h"
#include "third_party/blink/renderer/core/page/viewport_description.h"
#include "third_party/blink/renderer/platform/graphics/apply_viewport_changes.h"
#include "third_party/blink/renderer/platform/graphics/paint/paint_image.h"
#include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_associated_receiver.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_associated_remote.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_receiver.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_wrapper_mode.h"
#include "third_party/blink/renderer/platform/text/text_direction.h"
#include "third_party/blink/renderer/platform/widget/frame_widget.h"
#include "third_party/blink/renderer/platform/widget/widget_base_client.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
#include "ui/base/dragdrop/mojom/drag_drop_types.mojom-shared.h"
#include "ui/base/mojom/ui_base_types.mojom-shared.h"

namespace gfx {
class Point;
class PointF;
}  // namespace gfx

namespace blink {
class AnimationWorkletMutatorDispatcherImpl;
class FloatPoint;
class HitTestResult;
class HTMLPlugInElement;
class Page;
class PageWidgetEventHandler;
class PaintWorkletPaintDispatcher;
class RemoteFrame;
class WebLocalFrameImpl;
class WebPlugin;
class WebViewImpl;
class WidgetBase;
class ScreenMetricsEmulator;

// Implements WebFrameWidget for both main frames and child local root frame
// (OOPIF).
class CORE_EXPORT WebFrameWidgetImpl
    : public GarbageCollected<WebFrameWidgetImpl>,
      public WebFrameWidget,
      public WidgetBaseClient,
      public mojom::blink::FrameWidget,
      public viz::mojom::blink::InputTargetClient,
      public mojom::blink::FrameWidgetInputHandler,
      public FrameWidget,
      public PageWidgetEventHandler {
 public:
  WebFrameWidgetImpl(
      base::PassKey<WebLocalFrame>,
      CrossVariantMojoAssociatedRemote<
          mojom::blink::FrameWidgetHostInterfaceBase> frame_widget_host,
      CrossVariantMojoAssociatedReceiver<mojom::blink::FrameWidgetInterfaceBase>
          frame_widget,
      CrossVariantMojoAssociatedRemote<mojom::blink::WidgetHostInterfaceBase>
          widget_host,
      CrossVariantMojoAssociatedReceiver<mojom::blink::WidgetInterfaceBase>
          widget,
      scoped_refptr<base::SingleThreadTaskRunner> task_runner,
      const viz::FrameSinkId& frame_sink_id,
      bool hidden,
      bool never_composited,
      bool is_for_child_local_root,
      bool is_for_nested_main_frame);
  ~WebFrameWidgetImpl() override;

  virtual void Trace(Visitor*) const;

  // Shutdown the widget.
  void Close();

  // Returns the WebFrame that this widget is attached to. It will be a local
  // root since only local roots have a widget attached.
  WebLocalFrameImpl* LocalRootImpl() const { return local_root_; }

  // Returns the bounding box of the block type node touched by the WebPoint.
  gfx::Rect ComputeBlockBound(const gfx::Point& point_in_root_frame,
                              bool ignore_clipping) const;

  virtual void BindLocalRoot(WebLocalFrame&);

  // If this widget is for the top most main frame. This is different than
  // |ForMainFrame| because |ForMainFrame| could return true but this method
  // returns false. If this widget is a MainFrame widget embedded in another
  // widget, for example embedding a portal.
  bool ForTopMostMainFrame() const;

  // Adjusts whether the widget is nested or not. This is called during portal
  // transitions.
  void SetIsNestedMainFrameWidget(bool is_nested);

  // Returns true if this widget is for a local root that is a child frame,
  // false otherwise.
  bool ForSubframe() const { return is_for_child_local_root_; }

  // Opposite of |ForSubframe|. If this widget is for the local main frame.
  bool ForMainFrame() const { return !ForSubframe(); }

  // Called when the intrinsic size of the owning container is changing its
  // size. This should only be called when `ForSubframe` is true.
  void IntrinsicSizingInfoChanged(mojom::blink::IntrinsicSizingInfoPtr);

  void AutoscrollStart(const gfx::PointF& position);
  void AutoscrollFling(const gfx::Vector2dF& position);
  void AutoscrollEnd();

  bool HandleCurrentKeyboardEvent();

  // Creates or returns cached mutator dispatcher. This usually requires a
  // round trip to the compositor. The returned WeakPtr must only be
  // dereferenced on the output |mutator_task_runner|.
  base::WeakPtr<AnimationWorkletMutatorDispatcherImpl>
  EnsureCompositorMutatorDispatcher(
      scoped_refptr<base::SingleThreadTaskRunner> mutator_task_runner);

  // TODO: consider merge the input and return value to be one parameter.
  // Creates or returns cached paint dispatcher. The returned WeakPtr must only
  // be dereferenced on the output |paint_task_runner|.
  base::WeakPtr<PaintWorkletPaintDispatcher> EnsureCompositorPaintDispatcher(
      scoped_refptr<base::SingleThreadTaskRunner>* paint_task_runner);

  HitTestResult CoreHitTestResultAt(const gfx::PointF&);

  // FrameWidget overrides.
  cc::AnimationHost* AnimationHost() const final;
  void SetOverscrollBehavior(
      const cc::OverscrollBehavior& overscroll_behavior) final;
  void RequestAnimationAfterDelay(const base::TimeDelta&) final;
  void SetRootLayer(scoped_refptr<cc::Layer>) override;
  void RegisterSelection(cc::LayerSelection selection) final;
  void RequestDecode(const cc::PaintImage&,
                     base::OnceCallback<void(bool)>) override;
  void NotifyPresentationTimeInBlink(
      WebReportTimeCallback presentation_callback) final;
  void RequestBeginMainFrameNotExpected(bool request) final;
  int GetLayerTreeId() final;
  const cc::LayerTreeSettings& GetLayerTreeSettings() final;
  void UpdateBrowserControlsState(cc::BrowserControlsState constraints,
                                  cc::BrowserControlsState current,
                                  bool animate) final;
  void SetEventListenerProperties(cc::EventListenerClass,
                                  cc::EventListenerProperties) final;
  cc::EventListenerProperties EventListenerProperties(
      cc::EventListenerClass) const final;
  mojom::blink::DisplayMode DisplayMode() const override;
  const WebVector<gfx::Rect>& WindowSegments() const override;
  void SetDelegatedInkMetadata(
      std::unique_ptr<gfx::DelegatedInkMetadata> metadata) final;
  void DidOverscroll(const gfx::Vector2dF& overscroll_delta,
                     const gfx::Vector2dF& accumulated_overscroll,
                     const gfx::PointF& position,
                     const gfx::Vector2dF& velocity) override;
  void InjectGestureScrollEvent(WebGestureDevice device,
                                const gfx::Vector2dF& delta,
                                ui::ScrollGranularity granularity,
                                cc::ElementId scrollable_area_element_id,
                                WebInputEvent::Type injected_type) override;
  void DidChangeCursor(const ui::Cursor&) override;
  void GetCompositionCharacterBoundsInWindow(
      Vector<gfx::Rect>* bounds_in_dips) override;
  gfx::Range CompositionRange() override;
  WebTextInputInfo TextInputInfo() override;
  ui::mojom::VirtualKeyboardVisibilityRequest
  GetLastVirtualKeyboardVisibilityRequest() override;
  bool ShouldSuppressKeyboardForFocusedElement() override;
  void GetEditContextBoundsInWindow(
      absl::optional<gfx::Rect>* control_bounds,
      absl::optional<gfx::Rect>* selection_bounds) override;
  int32_t ComputeWebTextInputNextPreviousFlags() override;
  void ResetVirtualKeyboardVisibilityRequest() override;
  bool GetSelectionBoundsInWindow(gfx::Rect* focus,
                                  gfx::Rect* anchor,
                                  gfx::Rect* bounding_box,
                                  base::i18n::TextDirection* focus_dir,
                                  base::i18n::TextDirection* anchor_dir,
                                  bool* is_anchor_first) override;
  void ClearTextInputState() override;

  bool SetComposition(const String& text,
                      const Vector<ui::ImeTextSpan>& ime_text_spans,
                      const gfx::Range& replacement_range,
                      int selection_start,
                      int selection_end) override;
  void CommitText(const String& text,
                  const Vector<ui::ImeTextSpan>& ime_text_spans,
                  const gfx::Range& replacement_range,
                  int relative_cursor_pos) override;
  void FinishComposingText(bool keep_selection) override;
  bool IsProvisional() override;
  uint64_t GetScrollableContainerIdAt(
      const gfx::PointF& point_in_dips) override;
  bool ShouldHandleImeEvents() override;
  void SetEditCommandsForNextKeyEvent(
      Vector<mojom::blink::EditCommandPtr> edit_commands) override;
  Vector<ui::mojom::blink::ImeTextSpanInfoPtr> GetImeTextSpansInfo(
      const WebVector<ui::ImeTextSpan>& ime_text_spans) override;
  void RequestMouseLock(
      bool has_transient_user_activation,
      bool request_unadjusted_movement,
      mojom::blink::WidgetInputHandlerHost::RequestMouseLockCallback callback)
      override;
  gfx::RectF BlinkSpaceToDIPs(const gfx::RectF& rect) override;
  gfx::Rect BlinkSpaceToEnclosedDIPs(const gfx::Rect& rect) override;
  gfx::Size BlinkSpaceToFlooredDIPs(const gfx::Size& size) override;
  gfx::RectF DIPsToBlinkSpace(const gfx::RectF& rect) override;
  gfx::PointF DIPsToBlinkSpace(const gfx::PointF& point) override;
  gfx::Point DIPsToRoundedBlinkSpace(const gfx::Point& point) override;
  float DIPsToBlinkSpace(float scalar) override;
  void MouseCaptureLost() override;
  bool CanComposeInline() override;
  bool ShouldDispatchImeEventsToPlugin() override;
  void ImeSetCompositionForPlugin(const String& text,
                                  const Vector<ui::ImeTextSpan>& ime_text_spans,
                                  const gfx::Range& replacement_range,
                                  int selection_start,
                                  int selection_end) override;
  void ImeCommitTextForPlugin(const String& text,
                              const Vector<ui::ImeTextSpan>& ime_text_spans,
                              const gfx::Range& replacement_range,
                              int relative_cursor_pos) override;
  void ImeFinishComposingTextForPlugin(bool keep_selection) override;
  float GetCompositingScaleFactor() override;
  const cc::LayerTreeDebugState& GetLayerTreeDebugState() override;
  void SetLayerTreeDebugState(const cc::LayerTreeDebugState& state) override;

  // WebFrameWidget overrides.
  void InitializeNonCompositing(WebNonCompositedWidgetClient* client) override;
  WebLocalFrame* LocalRoot() const override;
  void UpdateCompositorScrollState(
      const cc::CompositorCommitData& commit_data) override;
  WebInputMethodController* GetActiveWebInputMethodController() const override;
  void DisableDragAndDrop() override;
  WebLocalFrameImpl* FocusedWebLocalFrameInWidget() const override;
  bool ScrollFocusedEditableElementIntoView() override;
  void ApplyViewportChangesForTesting(
      const ApplyViewportChangesArgs& args) override;
  void ApplyViewportIntersectionForTesting(
      mojom::blink::ViewportIntersectionStatePtr intersection_state);
  void NotifySwapAndPresentationTime(
      WebReportTimeCallback swap_callback,
      WebReportTimeCallback presentation_callback) override;
  scheduler::WebRenderWidgetSchedulingState* RendererWidgetSchedulingState()
      override;
  void WaitForDebuggerWhenShown() override;
  void SetTextZoomFactor(float text_zoom_factor) override;
  float TextZoomFactor() override;
  void SetMainFrameOverlayColor(SkColor) override;
  void AddEditCommandForNextKeyEvent(const WebString& name,
                                     const WebString& value) override;
  void ClearEditCommands() override;
  bool IsPasting() override;
  bool HandlingSelectRange() override;
  void ReleaseMouseLockAndPointerCaptureForTesting() override;
  const viz::FrameSinkId& GetFrameSinkId() override;
  WebHitTestResult HitTestResultAt(const gfx::PointF&) override;
  void SetZoomLevelForTesting(double zoom_level) override;
  void ResetZoomLevelForTesting() override;
  void SetDeviceScaleFactorForTesting(float factor) override;
  FrameWidgetTestHelper* GetFrameWidgetTestHelperForTesting() override;

  // Called when a drag-n-drop operation should begin.
  virtual void StartDragging(const WebDragData&,
                             DragOperationsMask,
                             const SkBitmap& drag_image,
                             const gfx::Point& drag_image_offset);

  bool DoingDragAndDrop() { return doing_drag_and_drop_; }
  static void SetIgnoreInputEvents(bool value) { ignore_input_events_ = value; }
  static bool IgnoreInputEvents() { return ignore_input_events_; }

  // Resets the layout tracking steps for the main frame. When
  // `UpdateLifecycle()` is called it generates `WebMeaningfulLayout` events
  // only once. This resets the state back to the default so it will fire new
  // events.
  void ResetMeaningfulLayoutStateForMainFrame();

  // WebWidget overrides.
  void InitializeCompositing(
      scheduler::WebAgentGroupScheduler& agent_group_scheduler,
      const ScreenInfos& screen_infos,
      const cc::LayerTreeSettings* settings) override;
  void SetCompositorVisible(bool visible) override;
  gfx::Size Size() override;
  void Resize(const gfx::Size& size_with_dsf) override;
  void SetCursor(const ui::Cursor& cursor) override;
  bool HandlingInputEvent() override;
  void SetHandlingInputEvent(bool handling) override;
  bool ImeCompositionReplacement() override;
  void ProcessInputEventSynchronouslyForTesting(const WebCoalescedInputEvent&,
                                                HandledEventCallback) override;
  WebInputEventResult DispatchBufferedTouchEvents() override;
  WebInputEventResult HandleInputEvent(const WebCoalescedInputEvent&) override;
  void UpdateTextInputState() override;
  void UpdateSelectionBounds() override;
  void ShowVirtualKeyboard() override;
  bool HasFocus() override;
  void SetFocus(bool focus) override;
  void FlushInputProcessedCallback() override;
  void CancelCompositionForPepper() override;
  void ApplyVisualProperties(
      const VisualProperties& visual_properties) override;
  bool PinchGestureActiveInMainFrame() override;
  float PageScaleInMainFrame() override;
  const ScreenInfo& GetScreenInfo() override;
  const ScreenInfos& GetScreenInfos() override;
  const ScreenInfo& GetOriginalScreenInfo() override;
  const ScreenInfos& GetOriginalScreenInfos() override;
  gfx::Rect WindowRect() override;
  gfx::Rect ViewRect() override;
  void SetScreenRects(const gfx::Rect& widget_screen_rect,
                      const gfx::Rect& window_screen_rect) override;
  gfx::Size VisibleViewportSizeInDIPs() override;
  bool IsHidden() const override;
  WebString GetLastToolTipTextForTesting() const override;
  float GetEmulatorScale() override;

  // WidgetBaseClient overrides:
  void BeginMainFrame(base::TimeTicks last_frame_time) override;
  void UpdateLifecycle(WebLifecycleUpdate requested_update,
                       DocumentUpdateReason reason) override;

  // mojom::blink::FrameWidget overrides:
  void ShowContextMenu(ui::mojom::MenuSourceType source_type,
                       const gfx::Point& location) override;
  void SetViewportIntersection(
      mojom::blink::ViewportIntersectionStatePtr intersection_state,
      const absl::optional<VisualProperties>& visual_properties) override;
  void DragSourceEndedAt(const gfx::PointF& point_in_viewport,
                         const gfx::PointF& screen_point,
                         ui::mojom::blink::DragOperation,
                         base::OnceClosure callback) override;

  // Sets the display mode, which comes from the top-level browsing context and
  // is applied to all widgets.
  void SetDisplayMode(mojom::blink::DisplayMode);

  absl::optional<gfx::Point> GetAndResetContextMenuLocation();

  void BindWidgetCompositor(
      mojo::PendingReceiver<mojom::blink::WidgetCompositor> receiver) override;

  void BindInputTargetClient(
      mojo::PendingReceiver<viz::mojom::blink::InputTargetClient> receiver)
      override;

  // viz::mojom::blink::InputTargetClient:
  void FrameSinkIdAt(const gfx::PointF& point,
                     const uint64_t trace_id,
                     FrameSinkIdAtCallback callback) override;

  // Called when the FrameView for this Widget's local root is created.
  void DidCreateLocalRootView();

  void SetZoomLevel(double zoom_level);

  // Called when the View has auto resized.
  void DidAutoResize(const gfx::Size& size);

  // This method returns the focused frame belonging to this WebWidget, that
  // is, a focused frame with the same local root as the one corresponding
  // to this widget. It will return nullptr if no frame is focused or, the
  // focused frame has a different local root.
  LocalFrame* FocusedLocalFrameInWidget() const;

  // For when the embedder itself change scales on the page (e.g. devtools)
  // and wants all of the content at the new scale to be crisp
  void SetNeedsRecalculateRasterScales();

  // Sets the background color to be filled in as gutter behind/around the
  // painted content. Non-composited WebViews need not implement this, as they
  // paint into another widget which has a background color of its own.
  void SetBackgroundColor(SkColor color);

  // Starts an animation of the page scale to a target scale factor and scroll
  // offset.
  // If use_anchor is true, destination is a point on the screen that will
  // remain fixed for the duration of the animation.
  // If use_anchor is false, destination is the final top-left scroll position.
  void StartPageScaleAnimation(const gfx::Vector2d& destination,
                               bool use_anchor,
                               float new_page_scale,
                               base::TimeDelta duration);

  // Called to update if scroll events should be sent.
  void SetHaveScrollEventHandlers(bool);

  // Start deferring commits to the compositor, allowing document lifecycle
  // updates without committing the layer tree. Commits are deferred
  // until at most the given |timeout| has passed. If multiple calls are made
  // when deferral is active then the initial timeout applies.
  void StartDeferringCommits(base::TimeDelta timeout);
  // Immediately stop deferring commits.
  void StopDeferringCommits(cc::PaintHoldingCommitTrigger);

  // Prevents any updates to the input for the layer tree, and the layer tree
  // itself, and the layer tree from becoming visible.
  std::unique_ptr<cc::ScopedDeferMainFrameUpdate> DeferMainFrameUpdate();

  // Sets the amount that the top and bottom browser controls are showing, from
  // 0 (hidden) to 1 (fully shown).
  void SetBrowserControlsShownRatio(float top_ratio, float bottom_ratio);

  // Set browser controls params. These params consist of top and bottom
  // heights, min-heights, browser_controls_shrink_blink_size, and
  // animate_browser_controls_height_changes. If
  // animate_browser_controls_height_changes is set to true, changes to the
  // browser controls height will be animated. If
  // browser_controls_shrink_blink_size is set to true, then Blink shrunk the
  // viewport clip layers by the top and bottom browser controls height. Top
  // controls will translate the web page down and do not immediately scroll
  // when hiding. The bottom controls scroll immediately and never translate the
  // content (only clip it).
  void SetBrowserControlsParams(cc::BrowserControlsParams params);

  // This function provides zooming for find in page results when browsing with
  // page autosize.
  void ZoomToFindInPageRect(const gfx::Rect& rect_in_root_frame);

  // Return the compositor LayerTreeHost.
  cc::LayerTreeHost* LayerTreeHostForTesting() const;
  // Ask compositor to composite a frame for testing. This will generate a
  // BeginMainFrame, and update the document lifecycle.
  void SynchronouslyCompositeForTesting(base::TimeTicks frame_time);

  // Adjust the synchronous resize mode for testing. Normally resizes are
  // asynchronous with sending the resize to the browser, however some tests
  // still need the resize to happen in a synchronous fashion.
  void UseSynchronousResizeModeForTesting(bool enable);

  // Sets the device color space for testing.
  void SetDeviceColorSpaceForTesting(const gfx::ColorSpace& color_space);

  // Converts from DIPs to Blink coordinate space (ie. Viewport/Physical
  // pixels).
  gfx::Size DIPsToCeiledBlinkSpace(const gfx::Size& size);

  void SetWindowRect(const gfx::Rect& window_rect);
  void SetWindowRectSynchronouslyForTesting(const gfx::Rect& new_window_rect);

  void UpdateTooltipUnderCursor(const String& tooltip_text, TextDirection dir);

  void ShowVirtualKeyboardOnElementFocus();
  void ProcessTouchAction(WebTouchAction touch_action);

  // Called to update whether low latency input mode is enabled or not.
  void SetNeedsLowLatencyInput(bool);

  // Requests unbuffered (ie. low latency) input until a pointerup
  // event occurs.
  void RequestUnbufferedInputEvents();

  // Requests unbuffered (ie. low latency) input due to debugger being
  // attached. Debugger needs to paint when stopped in the event handler.
  void SetNeedsUnbufferedInputForDebugger(bool);

  // Called when the main frame navigates.
  void DidNavigate();

  // Called when the widget should get targeting input.
  void SetMouseCapture(bool capture);

  // Sets the current page scale factor and minimum / maximum limits. Both
  // limits are initially 1 (no page scale allowed).
  void SetPageScaleStateAndLimits(float page_scale_factor,
                                  bool is_pinch_gesture_active,
                                  float minimum,
                                  float maximum);
  void UpdateViewportDescription(
      const ViewportDescription& viewport_description);

  // The value of the applied battery-savings META element in the document
  // changed.
  void BatterySavingsChanged(BatterySavingsFlags savings);

  const viz::LocalSurfaceId& LocalSurfaceIdFromParent();

  ScreenMetricsEmulator* DeviceEmulator();

  // Calculates the selection bounds in the root frame. Returns bounds unchanged
  // when there is no focused frame or no selection.
  void CalculateSelectionBounds(
      gfx::Rect& anchor_in_root_frame,
      gfx::Rect& focus_in_root_frame,
      gfx::Rect* bounding_box_in_root_frame = nullptr);

  // Returns if auto resize mode is enabled.
  bool AutoResizeMode();

  void SetScreenMetricsEmulationParameters(
      bool enabled,
      const blink::DeviceEmulationParams& params);
  void SetScreenInfoAndSize(const ScreenInfos& screen_infos,
                            const gfx::Size& widget_size,
                            const gfx::Size& visible_viewport_size);

  // Update the surface allocation information, compositor viewport rect and
  // screen info on the widget.
  void UpdateSurfaceAndScreenInfo(
      const viz::LocalSurfaceId& new_local_surface_id,
      const gfx::Rect& compositor_viewport_pixel_rect,
      const ScreenInfos& screen_infos);
  // Similar to UpdateSurfaceAndScreenInfo but the surface allocation
  // and compositor viewport rect remains the same.
  void UpdateScreenInfo(const ScreenInfos& screen_infos);
  void UpdateSurfaceAndCompositorRect(
      const viz::LocalSurfaceId& new_local_surface_id,
      const gfx::Rect& compositor_viewport_pixel_rect);
  void UpdateCompositorViewportRect(
      const gfx::Rect& compositor_viewport_pixel_rect);
  void SetWindowSegments(const std::vector<gfx::Rect>& window_segments);
  viz::FrameSinkId GetFrameSinkIdAtPoint(const gfx::PointF& point,
                                         gfx::PointF* local_point);

  // Set the pending window rect. For every SetPendingWindowRect
  // call there must be an AckPendingWindowRect call.
  void SetPendingWindowRect(const gfx::Rect& window_screen_rect);

  // Clear a previously set pending window rect. For every SetPendingWindowRect
  // call there must be an AckPendingWindowRect call.
  void AckPendingWindowRect();

  // Return the focused WebPlugin if there is one.
  WebPlugin* GetFocusedPluginContainer();

  // Return if there is a pending scale animation.
  bool HasPendingPageScaleAnimation();

  // Set the source URL for the compositor.
  void SetSourceURLForCompositor(ukm::SourceId source_id, const KURL& url);

  // Ask compositor to create the shared memory for smoothness ukm region.
  base::ReadOnlySharedMemoryRegion CreateSharedMemoryForSmoothnessUkm();

 protected:
  // WidgetBaseClient overrides:
  void ScheduleAnimation() override;
  void DidBeginMainFrame() override;
  std::unique_ptr<cc::LayerTreeFrameSink> AllocateNewLayerTreeFrameSink()
      override;

  // Whether compositing to LCD text should be auto determined. This can be
  // overridden by tests to disable this.
  virtual bool ShouldAutoDetermineCompositingToLCDTextSetting();

  // WebFrameWidget overrides.
  cc::LayerTreeHost* LayerTreeHost() override;

  bool doing_drag_and_drop_ = false;

 private:
  friend class WebViewImpl;
  friend class ReportTimeSwapPromise;

  // WidgetBaseClient overrides.
  void BeginCommitCompositorFrame() override;
  void EndCommitCompositorFrame(base::TimeTicks commit_start_time) override;
  void ApplyViewportChanges(const cc::ApplyViewportChangesArgs& args) override;
  void RecordDispatchRafAlignedInputTime(
      base::TimeTicks raf_aligned_input_start_time) override;
  void SetSuppressFrameRequestsWorkaroundFor704763Only(bool) override;
  void RecordStartOfFrameMetrics() override;
  void RecordEndOfFrameMetrics(
      base::TimeTicks,
      cc::ActiveFrameSequenceTrackers trackers) override;
  std::unique_ptr<cc::BeginMainFrameMetrics> GetBeginMainFrameMetrics()
      override;
  std::unique_ptr<cc::WebVitalMetrics> GetWebVitalMetrics() override;
  void BeginUpdateLayers() override;
  void EndUpdateLayers() override;
  void DidCommitAndDrawCompositorFrame() override;
  void DidObserveFirstScrollDelay(
      base::TimeDelta first_scroll_delay,
      base::TimeTicks first_scroll_timestamp) override;
  void DidCompletePageScaleAnimation() override;
  void FocusChangeComplete() override;
  bool WillHandleGestureEvent(const WebGestureEvent& event) override;
  void WillHandleMouseEvent(const WebMouseEvent& event) override;
  void ObserveGestureEventAndResult(
      const WebGestureEvent& gesture_event,
      const gfx::Vector2dF& unused_delta,
      const cc::OverscrollBehavior& overscroll_behavior,
      bool event_processed) override;
  bool SupportsBufferedTouchEvents() override { return true; }
  void DidHandleKeyEvent() override;
  WebTextInputType GetTextInputType() override;
  void SetCursorVisibilityState(bool is_visible) override;
  blink::FrameWidget* FrameWidget() override { return this; }
  void FocusChanged(bool enable) override;
  bool ShouldAckSyntheticInputImmediately() override;
  void UpdateVisualProperties(
      const VisualProperties& visual_properties) override;
  bool UpdateScreenRects(const gfx::Rect& widget_screen_rect,
                         const gfx::Rect& window_screen_rect) override;
  void OrientationChanged() override;
  void DidUpdateSurfaceAndScreen(
      const ScreenInfo& previous_original_screen_info) override;
  gfx::Rect ViewportVisibleRect() override;
  absl::optional<blink::mojom::ScreenOrientation> ScreenOrientationOverride()
      override;
  void WasHidden() override;
  void WasShown(bool was_evicted) override;
  void RunPaintBenchmark(int repeat_count,
                         cc::PaintBenchmarkResult& result) override;
  KURL GetURLForDebugTrace() override;
  float GetTestingDeviceScaleFactorOverride() override;
  void CountDroppedPointerDownForEventTiming(unsigned count) override;
  // mojom::blink::FrameWidget overrides.
  void DragTargetDragEnter(const WebDragData&,
                           const gfx::PointF& point_in_viewport,
                           const gfx::PointF& screen_point,
                           DragOperationsMask operations_allowed,
                           uint32_t key_modifiers,
                           DragTargetDragEnterCallback callback) override;
  void DragTargetDragOver(const gfx::PointF& point_in_viewport,
                          const gfx::PointF& screen_point,
                          DragOperationsMask operations_allowed,
                          uint32_t key_modifiers,
                          DragTargetDragOverCallback callback) override;
  void DragTargetDragLeave(const gfx::PointF& point_in_viewport,
                           const gfx::PointF& screen_point) override;
  void DragTargetDrop(const WebDragData&,
                      const gfx::PointF& point_in_viewport,
                      const gfx::PointF& screen_point,
                      uint32_t key_modifiers,
                      base::OnceClosure callback) override;
  void DragSourceSystemDragEnded() override;
  void SetBackgroundOpaque(bool opaque) override;
  void SetActive(bool active) override;
  // For both mainframe and childframe change the text direction of the
  // currently selected input field (if any).
  void SetTextDirection(base::i18n::TextDirection direction) override;
  // Sets the inherited effective touch action on an out-of-process iframe.
  void SetInheritedEffectiveTouchActionForSubFrame(
      WebTouchAction touch_action) override;
  // Toggles render throttling for an out-of-process iframe. Local frames are
  // throttled based on their visibility in the viewport, but remote frames
  // have to have throttling information propagated from parent to child
  // across processes.
  void UpdateRenderThrottlingStatusForSubFrame(bool is_throttled,
                                               bool subtree_throttled,
                                               bool display_locked) override;
  void EnableDeviceEmulation(const DeviceEmulationParams& parameters) override;
  void DisableDeviceEmulation() override;
  // Sets the inert bit on an out-of-process iframe, causing it to ignore
  // input.
  void SetIsInertForSubFrame(bool inert) override;
#if defined(OS_MAC)
  void GetStringAtPoint(const gfx::Point& point_in_local_root,
                        GetStringAtPointCallback callback) override;
#endif

  // mojom::blink::FrameWidgetInputHandler overrides.
  void AddImeTextSpansToExistingText(
      uint32_t start,
      uint32_t end,
      const Vector<ui::ImeTextSpan>& ime_text_spans) override;
  void ClearImeTextSpansByType(uint32_t start,
                               uint32_t end,
                               ui::ImeTextSpan::Type type) override;
  void SetCompositionFromExistingText(
      int32_t start,
      int32_t end,
      const Vector<ui::ImeTextSpan>& ime_text_spans) override;
  void ExtendSelectionAndDelete(int32_t before, int32_t after) override;
  void DeleteSurroundingText(int32_t before, int32_t after) override;
  void DeleteSurroundingTextInCodePoints(int32_t before,
                                         int32_t after) override;
  void SetEditableSelectionOffsets(int32_t start, int32_t end) override;
  void ExecuteEditCommand(const String& command, const String& value) override;
  void Undo() override;
  void Redo() override;
  void Cut() override;
  void Copy() override;
  void CopyToFindPboard() override;
  void Paste() override;
  void PasteAndMatchStyle() override;
  void Delete() override;
  void SelectAll() override;
  void CollapseSelection() override;
  void Replace(const String& word) override;
  void ReplaceMisspelling(const String& word) override;
  void SelectRange(const gfx::Point& base_in_dips,
                   const gfx::Point& extent_in_dips) override;
  void AdjustSelectionByCharacterOffset(
      int32_t start,
      int32_t end,
      mojom::blink::SelectionMenuBehavior behavior) override;
  void MoveRangeSelectionExtent(const gfx::Point& extent_in_dips) override;
  void ScrollFocusedEditableNodeIntoRect(
      const gfx::Rect& rect_in_dips) override;
  void MoveCaret(const gfx::Point& point_in_dips) override;
#if defined(OS_ANDROID)
  void SelectWordAroundCaret(SelectWordAroundCaretCallback callback) override;
#endif

  // PageWidgetEventHandler overrides:
  WebInputEventResult HandleKeyEvent(const WebKeyboardEvent&) override;
  void HandleMouseDown(LocalFrame&, const WebMouseEvent&) override;
  void HandleMouseLeave(LocalFrame&, const WebMouseEvent&) override;
  WebInputEventResult HandleMouseUp(LocalFrame&, const WebMouseEvent&) override;
  WebInputEventResult HandleGestureEvent(const WebGestureEvent&) override;
  WebInputEventResult HandleMouseWheel(LocalFrame&,
                                       const WebMouseWheelEvent&) override;
  WebInputEventResult HandleCharEvent(const WebKeyboardEvent&) override;

  WebInputEventResult HandleCapturedMouseEvent(const WebCoalescedInputEvent&);
  void MouseContextMenu(const WebMouseEvent&);
  void CancelDrag();
  void PresentationCallbackForMeaningfulLayout(blink::WebSwapResult,
                                               base::TimeTicks);

  void ForEachRemoteFrameControlledByWidget(
      const base::RepeatingCallback<void(RemoteFrame*)>& callback);

  void SetWindowRectSynchronously(const gfx::Rect& new_window_rect);

  void SendOverscrollEventFromImplSide(const gfx::Vector2dF& overscroll_delta,
                                       cc::ElementId scroll_latched_element_id);
  void SendScrollEndEventFromImplSide(cc::ElementId scroll_latched_element_id);

  void RecordManipulationTypeCounts(cc::ManipulationInfo info);

  // Finds the parameters required for scrolling the focused editable |element|
  // into view. |out_rect_to_scroll| is used for recursive scrolling of the
  // element into view and contains all or part of element's bounding box and
  // always includes the caret and is with respect to absolute coordinates.
  mojom::blink::ScrollIntoViewParamsPtr
  GetScrollParamsForFocusedEditableElement(const Element& element,
                                           PhysicalRect& out_rect_to_scroll);

  enum DragAction { kDragEnter, kDragOver };
  // Consolidate some common code between starting a drag over a target and
  // updating a drag over a target. If we're starting a drag, |isEntering|
  // should be true.
  ui::mojom::blink::DragOperation DragTargetDragEnterOrOver(
      const gfx::PointF& point_in_viewport,
      const gfx::PointF& screen_point,
      DragAction,
      uint32_t key_modifiers);

  // Helper function to call VisualViewport::viewportToRootFrame().
  gfx::PointF ViewportToRootFrame(const gfx::PointF& point_in_viewport) const;

  WebViewImpl* View() const;

  // Returns the page object associated with this widget. This may be null when
  // the page is shutting down, but will be valid at all other times.
  Page* GetPage() const;

  mojom::blink::FrameWidgetHost* GetAssociatedFrameWidgetHost() const;

  // Notifies RenderWidgetHostImpl that the frame widget has painted something.
  void DidMeaningfulLayout(WebMeaningfulLayout layout_type);

  // Enable or disable auto-resize. This is part of
  // UpdateVisualProperties though tests may call to it more directly.
  void SetAutoResizeMode(bool auto_resize,
                         const gfx::Size& min_size_before_dsf,
                         const gfx::Size& max_size_before_dsf,
                         float device_scale_factor);

  void ApplyViewportIntersection(
      mojom::blink::ViewportIntersectionStatePtr intersection_state);

  // Called when a gesture event has been processed.
  void DidHandleGestureEvent(const WebGestureEvent& event);

  // Called to update if pointerrawupdate events should be sent.
  void SetHasPointerRawUpdateEventHandlers(bool);

  // Helper function to process events while pointer locked.
  void PointerLockMouseEvent(const WebCoalescedInputEvent&);
  bool IsPointerLocked();

  // The fullscreen granted status from the most recent VisualProperties update.
  bool IsFullscreenGranted();

  // Set the compositing scale factor for this widget and notify remote frames
  // to update their compositing scale factor.
  void NotifyCompositingScaleFactorChanged(float compositing_scale_factor);

  void NotifyPageScaleFactorChanged(float page_scale_factor,
                                    bool is_pinch_gesture_active);

  // Helper for notifying frame-level objects that care about input events.
  // TODO: With some effort, this could be folded into a common implementation
  // of WebViewImpl::HandleInputEvent and WebFrameWidgetImpl::HandleInputEvent.
  void NotifyInputObservers(const WebCoalescedInputEvent& coalesced_event);

  Frame* FocusedCoreFrame() const;

  // Returns the currently focused `Element` in any `LocalFrame` owned by the
  // associated `WebView`.
  Element* FocusedElement() const;

  // Perform a hit test for a point relative to the root frame of the page.
  HitTestResult HitTestResultForRootFramePos(
      const FloatPoint& pos_in_root_frame);

  // Called during |UpdateVisualProperties| to apply the new size to the widget.
  void ApplyVisualPropertiesSizing(const VisualProperties& visual_properties);

  // Returns true iff the visual property state contains an update that will
  // change the fullscreen state (e.g. on/off or current display).
  bool DidChangeFullscreenState(
      const VisualProperties& visual_properties) const;

  // Returns the current state of synchronous resize mode for testing.
  bool SynchronousResizeModeForTestingEnabled();

  void NotifyZoomLevelChanged(LocalFrame* root);

  // A copy of the web drop data object we received from the browser.
  Member<DataObject> current_drag_data_;

  // The available drag operations (copy, move link...) allowed by the source.
  DragOperationsMask operations_allowed_ = kDragOperationNone;

  // The current drag operation as negotiated by the source and destination.
  // When not equal to DragOperationNone, the drag data can be dropped onto the
  // current drop target in this WebView (the drop target can accept the drop).
  ui::mojom::blink::DragOperation drag_operation_ =
      ui::mojom::blink::DragOperation::kNone;

  // This field stores drag/drop related info for the event that is currently
  // being handled. If the current event results in starting a drag/drop
  // session, this info is sent to the browser along with other drag/drop info.
  mojom::blink::DragEventSourceInfo possible_drag_event_info_;

  // Base functionality all widgets have. This is a member as to avoid
  // complicated inheritance structures.
  std::unique_ptr<WidgetBase> widget_base_;

  // Compositing scale factor for all frames attached to this widget sent from
  // the remote parent frame.
  float compositing_scale_factor_ = 1.f;

  // The last seen page scale state, which comes from the main frame if we're
  // in a child frame. This state is propagated through the RenderWidget tree
  // passed to any new child RenderWidget.
  float page_scale_factor_in_mainframe_ = 1.f;
  bool is_pinch_gesture_active_in_mainframe_ = false;

  // If set, the (plugin) element which has mouse capture.
  Member<HTMLPlugInElement> mouse_capture_element_;

  // The size of the widget in viewport coordinates. This is slightly different
  // than the WebViewImpl::size_ since isn't set in auto resize mode.
  absl::optional<gfx::Size> size_;

  static bool ignore_input_events_;

  const viz::FrameSinkId frame_sink_id_;

  // WebFrameWidget is associated with a subtree of the frame tree,
  // corresponding to a maximal connected tree of LocalFrames. This member
  // points to the root of that subtree.
  Member<WebLocalFrameImpl> local_root_;

  mojom::blink::DisplayMode display_mode_;

  WebVector<gfx::Rect> window_segments_;

  // This is owned by the LayerTreeHostImpl, and should only be used on the
  // compositor thread, so we keep the TaskRunner where you post tasks to
  // make that happen.
  base::WeakPtr<AnimationWorkletMutatorDispatcherImpl> mutator_dispatcher_;
  scoped_refptr<base::SingleThreadTaskRunner> mutator_task_runner_;

  // The |paint_dispatcher_| should only be dereferenced on the
  // |paint_task_runner_| (in practice this is the compositor thread). We keep a
  // copy of it here to provide to new PaintWorkletProxyClient objects (which
  // run on the worklet thread) so that they can talk to the
  // PaintWorkletPaintDispatcher on the compositor thread.
  base::WeakPtr<PaintWorkletPaintDispatcher> paint_dispatcher_;
  scoped_refptr<base::SingleThreadTaskRunner> paint_task_runner_;

  // WebFrameWidgetImpl is not tied to ExecutionContext
  HeapMojoAssociatedRemote<mojom::blink::FrameWidgetHost> frame_widget_host_{
      nullptr};
  // WebFrameWidgetImpl is not tied to ExecutionContext
  HeapMojoAssociatedReceiver<mojom::blink::FrameWidget, WebFrameWidgetImpl>
      receiver_{this, nullptr};
  HeapMojoReceiver<viz::mojom::blink::InputTargetClient, WebFrameWidgetImpl>
      input_target_receiver_{this, nullptr};

  // Different consumers in the browser process makes different assumptions, so
  // must always send the first IPC regardless of value.
  absl::optional<bool> has_touch_handlers_;

  Vector<mojom::blink::EditCommandPtr> edit_commands_;

  absl::optional<gfx::Point> host_context_menu_location_;
  uint32_t last_capture_sequence_number_ = 0u;

  // Indicates whether tab-initiated fullscreen was granted.
  bool is_fullscreen_granted_ = false;

  // Indicates whether we need to consume scroll gestures to move cursor.
  bool swipe_to_move_cursor_activated_ = false;

  // Set when a measurement begins, reset when the measurement is taken.
  absl::optional<base::TimeTicks> update_layers_start_time_;

  // Metrics for gathering time for commit of compositor frame.
  absl::optional<base::TimeTicks> commit_compositor_frame_start_time_;

  // Present when emulation is enabled, only on a main frame's WebFrameWidget.
  // Used to override values given from the browser such as ScreenInfo,
  // WidgetScreenRect, WindowScreenRect, and the widget's size.
  Member<ScreenMetricsEmulator> device_emulator_;

  // keyPress events to be suppressed if the associated keyDown event was
  // handled.
  bool suppress_next_keypress_event_ = false;

  // Whether drag and drop is supported by this widget. When disabled
  // any drag operation that is started will be canceled immediately.
  bool drag_and_drop_disabled_ = false;

  // A callback client for non-composited frame widgets.
  WebNonCompositedWidgetClient* non_composited_client_ = nullptr;

  // This struct contains data that is only valid for child local root widgets.
  // You should use `child_data()` to access it.
  struct ChildLocalRootData {
    gfx::Rect compositor_visible_rect;
    bool did_suspend_parsing = false;
  } child_local_root_data_;

  ChildLocalRootData& child_data() {
    DCHECK(ForSubframe());
    return child_local_root_data_;
  }

  // Web tests override the zoom factor in the renderer with this. We store it
  // to keep the override if the browser passes along VisualProperties with the
  // real device scale factor. A value of -INFINITY means this is ignored.
  // It is always valid to read this variable but it can only be set for main
  // frame widgets.
  double zoom_level_for_testing_ = -INFINITY;

  // Web tests override the device scale factor in the renderer with this. We
  // store it to keep the override if the browser passes along VisualProperties
  // with the real device scale factor. A value of 0.f means this is ignored.
  // It is always valid to read this variable but it can only be set for main
  // frame widgets.
  float device_scale_factor_for_testing_ = 0;

  // This struct contains data that is only valid for main frame widgets.
  // You should use `main_data()` to access it.
  struct MainFrameData {
    // `UpdateLifecycle()` generates `WebMeaningfulLayout` events these
    // variables track what events should be generated. They are only applicable
    // for main frame widgets.
    bool should_dispatch_first_visually_non_empty_layout = false;
    bool should_dispatch_first_layout_after_finished_parsing = false;
    bool should_dispatch_first_layout_after_finished_loading = false;
    // Last background color sent to the browser. Only set for main frames.
    absl::optional<SkColor> last_background_color;
    // This bit is used to tell if this is a nested widget (an "inner web
    // contents") like a <webview> or <portal> widget. If false, the widget is
    // the top level widget.
    bool is_for_nested_main_frame = false;

    // In web tests, synchronous resizing mode may be used. Normally each
    // widget's size is controlled by IPC from the browser. In synchronous
    // resize mode the renderer controls the size directly, and IPCs from the
    // browser must be ignored. This was deprecated but then later undeprecated,
    // so it is now called unfortunate instead. See https://crbug.com/309760.
    // When this is enabled the various size properties will be controlled
    // directly when SetWindowRect() is called instead of needing a round trip
    // through the browser. Note that SetWindowRectSynchronouslyForTesting()
    // provides a secondary way to control the size of the FrameWidget
    // independently from the renderer process, without the use of this mode,
    // however it would be overridden by the browser if they disagree.
    bool synchronous_resize_mode_for_testing = false;

  } main_frame_data_;

  MainFrameData& main_data() {
    DCHECK(ForMainFrame());
    return main_frame_data_;
  }

  const MainFrameData& main_data() const {
    DCHECK(ForMainFrame());
    return main_frame_data_;
  }

  // Whether this widget is for a child local root, or otherwise a main frame.
  const bool is_for_child_local_root_;

  // This stores the last hidden page popup. If a GestureTap attempts to open
  // the popup that is closed by its previous GestureTapDown, the popup remains
  // closed.
  scoped_refptr<WebPagePopupImpl> last_hidden_page_popup_;

  base::WeakPtrFactory<mojom::blink::FrameWidgetInputHandler>
      input_handler_weak_ptr_factory_{this};
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_WEB_FRAME_WIDGET_IMPL_H_