OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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_RENDERER_INPUT_FRAME_INPUT_HANDLER_IMPL_H_ |
| 6 #define CONTENT_RENDERER_INPUT_FRAME_INPUT_HANDLER_IMPL_H_ |
| 7 |
| 8 #include "base/memory/ref_counted.h" |
| 9 #include "content/common/input/input_handler.mojom.h" |
| 10 #include "content/renderer/render_frame_impl.h" |
| 11 #include "mojo/public/cpp/bindings/binding.h" |
| 12 |
| 13 namespace content { |
| 14 class MainThreadEventQueue; |
| 15 |
| 16 // This class provides an implementation of FrameInputHandler mojo interface. |
| 17 // When a compositor thread is being used in the renderer the mojo channel |
| 18 // is bound on the compositor thread. Method calls, and events received on the |
| 19 // compositor thread are then placed in the MainThreadEventQueue for |
| 20 // the associated RenderWidget. This is done as to ensure that input related |
| 21 // messages and events that are handled on the compositor thread aren't |
| 22 // executed before other input events that need to be processed on the |
| 23 // main thread. ie. Since some messages flow to the compositor thread |
| 24 // all input needs to flow there so the ordering of events is kept in sequence. |
| 25 // |
| 26 // eg. (B = Browser, CT = Compositor Thread, MT = Main Thread) |
| 27 // B sends MouseEvent |
| 28 // B sends Copy message |
| 29 // CT receives MouseEvent (CT might do something with the MouseEvent) |
| 30 // CT places MouseEvent in MainThreadEventQueue |
| 31 // CT receives Copy message (CT has no use for the Copy message) |
| 32 // CT places Copy message in MainThreadEventQueue |
| 33 // MT receives MouseEvent |
| 34 // MT receives Copy message |
| 35 // |
| 36 // When a compositor thread isn't used the mojo channel is just bound |
| 37 // on the main thread and messages are handled right away. |
| 38 class FrameInputHandlerImpl |
| 39 : public mojom::FrameInputHandler, |
| 40 public base::RefCountedThreadSafe<FrameInputHandlerImpl> { |
| 41 public: |
| 42 static void CreateMojoService( |
| 43 RenderFrameImpl* render_frame, |
| 44 const service_manager::BindSourceInfo& source_info, |
| 45 mojom::FrameInputHandlerRequest request); |
| 46 |
| 47 void SetCompositionFromExistingText( |
| 48 int32_t start, |
| 49 int32_t end, |
| 50 const std::vector<ui::CompositionUnderline>& underlines) override; |
| 51 void ExtendSelectionAndDelete(int32_t before, int32_t after) override; |
| 52 void DeleteSurroundingText(int32_t before, int32_t after) override; |
| 53 void DeleteSurroundingTextInCodePoints(int32_t before, |
| 54 int32_t after) override; |
| 55 void SetEditableSelectionOffsets(int32_t start, int32_t end) override; |
| 56 void ExecuteEditCommand(const std::string& command, |
| 57 const base::Optional<base::string16>& value) override; |
| 58 void Undo() override; |
| 59 void Redo() override; |
| 60 void Cut() override; |
| 61 void Copy() override; |
| 62 void CopyToFindPboard() override; |
| 63 void Paste() override; |
| 64 void PasteAndMatchStyle() override; |
| 65 void Replace(const base::string16& word) override; |
| 66 void ReplaceMisspelling(const base::string16& word) override; |
| 67 void Delete() override; |
| 68 void SelectAll() override; |
| 69 void CollapseSelection() override; |
| 70 void SelectRange(const gfx::Point& base, const gfx::Point& extent) override; |
| 71 void AdjustSelectionByCharacterOffset(int32_t start, int32_t end) override; |
| 72 void MoveRangeSelectionExtent(const gfx::Point& extent) override; |
| 73 |
| 74 protected: |
| 75 friend class base::RefCountedThreadSafe<FrameInputHandlerImpl>; |
| 76 ~FrameInputHandlerImpl() override; |
| 77 |
| 78 private: |
| 79 enum class UpdateState { kNone, kIsPasting, kIsSelectingRange }; |
| 80 |
| 81 class HandlingState { |
| 82 public: |
| 83 HandlingState(RenderFrameImpl* render_frame, UpdateState state); |
| 84 ~HandlingState(); |
| 85 |
| 86 private: |
| 87 RenderFrameImpl* render_frame_; |
| 88 bool original_select_range_value_; |
| 89 bool original_pasting_value_; |
| 90 }; |
| 91 |
| 92 FrameInputHandlerImpl(RenderFrameImpl* render_frame, |
| 93 mojom::FrameInputHandlerRequest request); |
| 94 |
| 95 void RunOnMainThread(const base::Closure& closure); |
| 96 void BindOnCompositor(mojom::FrameInputHandlerRequest request); |
| 97 void BindNow(mojom::FrameInputHandlerRequest request); |
| 98 void ExecuteCommandOnMainThread(const std::string& command, |
| 99 UpdateState state); |
| 100 |
| 101 RenderFrameImpl* GetRenderFrame(); |
| 102 |
| 103 mojo::Binding<mojom::FrameInputHandler> binding_; |
| 104 |
| 105 // |render_frame_| should only be accessed on the main thread. Use |
| 106 // GetRenderFrame so that it will DCHECK this for you. |
| 107 RenderFrameImpl* render_frame_; |
| 108 |
| 109 scoped_refptr<MainThreadEventQueue> input_event_queue_; |
| 110 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
| 111 |
| 112 DISALLOW_COPY_AND_ASSIGN(FrameInputHandlerImpl); |
| 113 }; |
| 114 |
| 115 } // namespace content |
| 116 |
| 117 #endif // CONTENT_RENDERER_INPUT_FRAME_INPUT_HANDLER_IMPL_H_ |
OLD | NEW |