[M108 Migration] Fix incorrect module dependancy 08/286708/2
authorGajendra N <gajendra.n@samsung.com>
Wed, 11 Jan 2023 11:45:35 +0000 (17:15 +0530)
committerBot Blink <blinkbot@samsung.com>
Fri, 13 Jan 2023 01:11:21 +0000 (01:11 +0000)
Fixing dependency issue : `ui/` shouldn't depend on `content/`, which
may result in build breaks caused by not yet generated mojo files.

IMContentEfl which resides in ui layer had a direct dependancy on
content::RenderWidgetHostImpl, which is incorrect as per chromium
guidelines. Instead, introduce a public helper class as proxy to
route calls at content layer.

Reference: https://review.tizen.org/gerrit/285551

Change-Id: Ia1ecd29fc9badf58e89c997b6c081880de1c4f66
Signed-off-by: Gajendra N <gajendra.n@samsung.com>
tizen_src/chromium_impl/content/browser/renderer_host/rwhv_aura_offscreen_helper_efl.cc
tizen_src/chromium_impl/content/browser/renderer_host/rwhv_aura_offscreen_helper_efl.h
tizen_src/chromium_impl/content/public/browser/render_widget_host_helper.h [new file with mode: 0644]
tizen_src/chromium_impl/ui/ozone/platform/efl/im_context_efl.cc
tizen_src/chromium_impl/ui/ozone/platform/efl/im_context_efl.h

index ef0542e..c7b0b2e 100644 (file)
@@ -11,6 +11,7 @@
 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
 #include "content/browser/web_contents/web_contents_impl.h"
 #include "content/browser/web_contents/web_contents_view_aura.h"
+#include "content/public/browser/render_widget_host_helper.h"
 #include "content/public/browser/web_contents_delegate.h"
 #include "gpu/command_buffer/service/texture_base.h"
 #include "skia/ext/image_operations.h"
 
 namespace content {
 
+class RenderWidgetHostHelperAura : public RenderWidgetHostHelper {
+ public:
+  explicit RenderWidgetHostHelperAura(RWHVAuraOffscreenHelperEfl* rwhv_helper)
+      : rwhv_helper_(rwhv_helper) {}
+  ~RenderWidgetHostHelperAura() override = default;
+
+  bool HasRenderWidgetHost() const override {
+    return !!rwhv_helper_->GetRenderWidgetHostImpl();
+  }
+
+  void ExtendSelectionAndDelete(int32_t before, int32_t after) override {
+    auto* handler = GetFrameWidgetInputHandler();
+    if (!handler)
+      return;
+
+    handler->ExtendSelectionAndDelete(before, after);
+  }
+
+  void SetCompositionFromExistingText(
+      int32_t start,
+      int32_t end,
+      const std::vector<ui::ImeTextSpan>& ime_text_spans) override {
+    auto* handler = GetFrameWidgetInputHandler();
+    if (!handler)
+      return;
+
+    handler->SetCompositionFromExistingText(start, end, ime_text_spans);
+  }
+
+  void ImeCommitText(const std::u16string& text,
+                     const std::vector<ui::ImeTextSpan>& ime_text_spans,
+                     const gfx::Range& replacement_range,
+                     int relative_cursor_pos) override {
+    auto* rwhi = rwhv_helper_->GetRenderWidgetHostImpl();
+    if (!rwhi)
+      return;
+
+    rwhi->ImeCommitText(text, ime_text_spans, replacement_range,
+                        relative_cursor_pos);
+  }
+
+  void ImeFinishComposingText(bool keep_selection) override {
+    auto* rwhi = rwhv_helper_->GetRenderWidgetHostImpl();
+    if (!rwhi)
+      return;
+
+    rwhi->ImeFinishComposingText(keep_selection);
+  }
+
+  void ImeSetComposition(const std::u16string& text,
+                         const std::vector<ui::ImeTextSpan>& ime_text_spans,
+                         const gfx::Range& replacement_range,
+                         int selection_start,
+                         int selection_end) override {
+    auto* rwhi = rwhv_helper_->GetRenderWidgetHostImpl();
+    if (!rwhi)
+      return;
+
+    rwhi->ImeSetComposition(text, ime_text_spans, replacement_range,
+                            selection_start, selection_end);
+  }
+
+  bool ExistsSelectedText() override { return false; }
+
+  bool ImeHandleKeyEventEnabled() override { return true; }
+
+  gfx::Size GetPhysicalBackingSize() const override {
+    return rwhv_helper_->GetPhysicalBackingSize();
+  }
+
+  Evas_Object* EwkView() const override { return rwhv_helper_->ewk_view(); }
+
+ private:
+  blink::mojom::FrameWidgetInputHandler* GetFrameWidgetInputHandler() const {
+    auto* rwhi = rwhv_helper_->GetRenderWidgetHostImpl();
+    if (!rwhi)
+      return nullptr;
+
+    return rwhi->GetFrameWidgetInputHandler();
+  }
+
+  RWHVAuraOffscreenHelperEfl* rwhv_helper_;
+};
+
 RWHVAuraOffscreenHelperEfl::RWHVAuraOffscreenHelperEfl(
     RenderWidgetHostViewAura* rwhva,
     WebContents* web_contents)
-    : rwhv_aura_(rwhva), web_contents_(web_contents) {
+    : rwhv_aura_(rwhva),
+      web_contents_(web_contents),
+      rwh_helper_(std::make_unique<RenderWidgetHostHelperAura>(this)) {
   Initialize();
 }
 
@@ -576,7 +663,7 @@ ui::IMContextEfl* RWHVAuraOffscreenHelperEfl::GetIMContextEfl() {
   if (!im_context_efl_) {
     if (GetEventHandler() && GetEventHandler()->GetIMContextEfl()) {
       im_context_efl_ = GetEventHandler()->GetIMContextEfl();
-      im_context_efl_->SetRWHVHelper(this);
+      im_context_efl_->SetRWHHelper(rwh_helper_.get());
       return im_context_efl_;
     }
     LOG(ERROR) << "im_context_efl_ is not set";
index 35fc17c..004a800 100644 (file)
@@ -34,6 +34,7 @@ class IMContextEfl;
 
 namespace content {
 
+class RenderWidgetHostHelper;
 class RenderWidgetHostImpl;
 class RenderWidgetHostViewAura;
 class WebContents;
@@ -136,6 +137,8 @@ class CONTENT_EXPORT RWHVAuraOffscreenHelperEfl {
   ui::IMContextEfl* im_context_efl_ = nullptr;
   RenderWidgetHostViewAura* rwhv_aura_ = nullptr;
   WebContents* web_contents_ = nullptr;
+
+  std::unique_ptr<RenderWidgetHostHelper> rwh_helper_;
 };
 
 }  // namespace content
diff --git a/tizen_src/chromium_impl/content/public/browser/render_widget_host_helper.h b/tizen_src/chromium_impl/content/public/browser/render_widget_host_helper.h
new file mode 100644 (file)
index 0000000..743a4c0
--- /dev/null
@@ -0,0 +1,59 @@
+// Copyright 2022 Samsung Electronics Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_PUBLIC_BROWSER_RENDER_WIDGET_HOST_HELPER_H_
+#define CONTENT_PUBLIC_BROWSER_RENDER_WIDGET_HOST_HELPER_H_
+
+#include <Ecore_Evas.h>
+
+#include <vector>
+
+#include "content/common/content_export.h"
+#include "ui/base/ime/ime_text_span.h"
+#include "ui/gfx/geometry/size.h"
+#include "ui/gfx/range/range.h"
+
+namespace content {
+
+// Class used as IME input proxy. See `ImContextEfl`.
+class CONTENT_EXPORT RenderWidgetHostHelper {
+ public:
+  RenderWidgetHostHelper() = default;
+  virtual ~RenderWidgetHostHelper() = default;
+
+  RenderWidgetHostHelper(const RenderWidgetHostHelper&) = delete;
+  RenderWidgetHostHelper& operator=(const RenderWidgetHostHelper&) = delete;
+
+  virtual bool HasRenderWidgetHost() const = 0;
+
+  // IM related APIs defined in `RenderWidgetHostImpl`
+  virtual void ExtendSelectionAndDelete(int32_t before, int32_t after) = 0;
+  virtual void SetCompositionFromExistingText(
+      int32_t start,
+      int32_t end,
+      const std::vector<ui::ImeTextSpan>& ime_text_spans) = 0;
+  virtual void ImeCommitText(const std::u16string& text,
+                             const std::vector<ui::ImeTextSpan>& ime_text_spans,
+                             const gfx::Range& replacement_range,
+                             int relative_cursor_pos) = 0;
+  virtual void ImeFinishComposingText(bool keep_selection) = 0;
+  virtual void ImeSetComposition(
+      const std::u16string& text,
+      const std::vector<ui::ImeTextSpan>& ime_text_spans,
+      const gfx::Range& replacement_range,
+      int selection_start,
+      int selection_end) = 0;
+
+  // API defined `SelectionControllerEfl`
+  virtual bool ExistsSelectedText() = 0;
+
+  // APIs defined in `RenderWidgetHostViewAuraHelperEfl`
+  virtual bool ImeHandleKeyEventEnabled() = 0;
+  virtual gfx::Size GetPhysicalBackingSize() const = 0;
+  virtual Evas_Object* EwkView() const = 0;
+};
+
+}  // namespace content
+
+#endif  // CONTENT_PUBLIC_BROWSER_RENDER_WIDGET_HOST_HELPER_H_
index b7fb24d..234085f 100644 (file)
@@ -9,11 +9,10 @@
 
 #include "base/logging.h"
 #include "base/strings/utf_string_conversions.h"
-#include "content/browser/renderer_host/render_widget_host_impl.h"
-#include "content/browser/renderer_host/rwhv_aura_offscreen_helper_efl.h"
-#include "content/public/browser/web_contents_delegate.h"
+#include "content/public/browser/render_widget_host_helper.h"
 #include "tizen/system_info.h"
 #include "ui/base/ime/ime_text_span.h"
+#include "ui/events/event.h"
 #include "ui/ozone/platform/efl/efl_event_handler.h"
 #include "ui/ozone/platform/efl/efl_platform_event_source.h"
 #include "ui/ozone/platform/efl/efl_window.h"
@@ -591,15 +590,15 @@ void IMContextEfl::OnPreeditChanged(void* data,
 
 void IMContextEfl::OnInputPanelStateChanged(int state) {
   if (state == ECORE_IMF_INPUT_PANEL_STATE_SHOW) {
-    if (rwhv_helper_ && rwhv_helper_->ewk_view()) {
+    if (rwh_helper_ && rwh_helper_->EwkView()) {
       is_showing_ = true;
-      evas_object_smart_callback_call(rwhv_helper_->ewk_view(),
+      evas_object_smart_callback_call(rwh_helper_->EwkView(),
                                       "editorclient,ime,opened", 0);
     }
   } else if (state == ECORE_IMF_INPUT_PANEL_STATE_HIDE) {
-    if (rwhv_helper_ && rwhv_helper_->ewk_view()) {
+    if (rwh_helper_ && rwh_helper_->EwkView()) {
       is_showing_ = false;
-      evas_object_smart_callback_call(rwhv_helper_->ewk_view(),
+      evas_object_smart_callback_call(rwh_helper_->EwkView(),
                                       "editorclient,ime,closed", 0);
     }
   }
@@ -609,19 +608,19 @@ void IMContextEfl::OnInputPanelGeometryChanged() {
   Eina_Rectangle rect;
   ecore_imf_context_input_panel_geometry_get(context_, &rect.x, &rect.y,
                                              &rect.w, &rect.h);
-  if (rwhv_helper_ && rwhv_helper_->ewk_view()) {
-    evas_object_smart_callback_call(rwhv_helper_->ewk_view(),
+  if (rwh_helper_ && rwh_helper_->EwkView()) {
+    evas_object_smart_callback_call(rwh_helper_->EwkView(),
                                     "inputmethod,changed",
                                     static_cast<void*>(&rect));
   }
 }
 void IMContextEfl::OnCandidateInputPanelStateChanged(int state) {
-  if (rwhv_helper_ && rwhv_helper_->ewk_view()) {
+  if (rwh_helper_ && rwh_helper_->EwkView()) {
     if (state == ECORE_IMF_CANDIDATE_PANEL_SHOW) {
-      evas_object_smart_callback_call(rwhv_helper_->ewk_view(),
+      evas_object_smart_callback_call(rwh_helper_->EwkView(),
                                       "editorclient,candidate,opened", 0);
     } else {
-      evas_object_smart_callback_call(rwhv_helper_->ewk_view(),
+      evas_object_smart_callback_call(rwh_helper_->EwkView(),
                                       "editorclient,candidate,closed", 0);
     }
   }
@@ -651,8 +650,7 @@ bool IMContextEfl::OnRetrieveSurrounding(char** text, int* offset) {
 }
 
 void IMContextEfl::OnDeleteSurrounding(void* event_info) {
-  auto rwhi = GetRenderWidgetHostImpl();
-  if (!rwhi) {
+  if (!HasRenderWidgetHostImpl()) {
     LOG(ERROR) << "rwhi is nullptr";
     return;
   }
@@ -667,9 +665,8 @@ void IMContextEfl::OnDeleteSurrounding(void* event_info) {
   int after = event->n_chars + event->offset;
 
   if (is_transaction_finished_) {
-    if (rwhi->GetFrameWidgetInputHandler()) {
-      rwhi->GetFrameWidgetInputHandler()->ExtendSelectionAndDelete(before,
-                                                                   after);
+    if (rwh_helper_) {
+      rwh_helper_->ExtendSelectionAndDelete(before, after);
     }
   } else {
     int begin = event->offset < 0 ? 0 : event->offset;
@@ -681,17 +678,14 @@ void IMContextEfl::OnDeleteSurrounding(void* event_info) {
     text_span.underline_style = ui::ImeTextSpan::UnderlineStyle::kNone;
 #endif
     ime_text_spans.push_back(text_span);
-    if (rwhi->GetFrameWidgetInputHandler()) {
-      rwhi->GetFrameWidgetInputHandler()->SetCompositionFromExistingText(
-          begin, end, ime_text_spans);
+    if (rwh_helper_) {
+      rwh_helper_->SetCompositionFromExistingText(begin, end, ime_text_spans);
     }
   }
 }
 
 void IMContextEfl::OnCandidateInputPanelLanguageChanged(Ecore_IMF_Context*) {
-  auto rwhi = GetRenderWidgetHostImpl();
-
-  if (!rwhi || composition_.text.length() == 0)
+  if (!HasRenderWidgetHostImpl() || composition_.text.length() == 0)
     return;
 
   CancelComposition();
@@ -717,12 +711,12 @@ bool IMContextEfl::IsFocused() const {
 }
 
 bool IMContextEfl::WebViewWillBeResized() {
-  if (!context_ || !rwhv_helper_)
+  if (!context_ || !rwh_helper_)
     return false;
 
   return IsVisible()
-             ? default_view_size_ == rwhv_helper_->GetPhysicalBackingSize()
-             : default_view_size_ != rwhv_helper_->GetPhysicalBackingSize();
+             ? default_view_size_ == rwh_helper_->GetPhysicalBackingSize()
+             : default_view_size_ != rwh_helper_->GetPhysicalBackingSize();
 }
 
 void IMContextEfl::ClearQueues() {
@@ -858,21 +852,21 @@ void IMContextEfl::ProcessNextPreeditText(bool processed) {
     // if text is selected status.
     bool text_selected = composition_text.text.length() == 0;
 #if !defined(EWK_BRINGUP)
-    if (rwhv_helper_) {
+    if (rwh_helper_) {
       text_selected =
-          text_selected && rwhv_helper_->GetSelectionController() &&
-          rwhv_helper_->GetSelectionController()->ExistsSelectedText();
+          text_selected && rwh_helper_->GetSelectionController() &&
+          rwh_helper_->GetSelectionController()->ExistsSelectedText();
     }
 #endif
     if (!text_selected) {
-      if (auto rwhi = GetRenderWidgetHostImpl()) {
+      if (HasRenderWidgetHostImpl()) {
         const std::vector<ImeTextSpan>& underlines =
             reinterpret_cast<const std::vector<ImeTextSpan>&>(
                 composition_text.ime_text_spans);
-        rwhi->ImeSetComposition(composition_text.text, underlines,
-                                gfx::Range::InvalidRange(),
-                                composition_text.selection.start(),
-                                composition_text.selection.end());
+        rwh_helper_->ImeSetComposition(composition_text.text, underlines,
+                                       gfx::Range::InvalidRange(),
+                                       composition_text.selection.start(),
+                                       composition_text.selection.end());
       } else
         LOG(ERROR) << "rwhi is nullptr";
     }
@@ -913,22 +907,21 @@ void IMContextEfl::PushToKeyDownEventQueue(KeyEvent key) {
   keydown_event_queue_.push(key);
 }
 
-content::RenderWidgetHostImpl* IMContextEfl::GetRenderWidgetHostImpl() const {
-  return rwhv_helper_ ? rwhv_helper_->GetRenderWidgetHostImpl() : nullptr;
+bool IMContextEfl::HasRenderWidgetHostImpl() const {
+  return rwh_helper_ && rwh_helper_->HasRenderWidgetHost();
 }
 
 void IMContextEfl::ConfirmComposition(std::u16string& text) {
-  auto rwhi = GetRenderWidgetHostImpl();
-  if (!rwhi) {
+  if (!HasRenderWidgetHostImpl()) {
     LOG(ERROR) << "rwhi is nullptr";
     return;
   }
 
   if (text.length()) {
-    rwhi->ImeCommitText(text, std::vector<ImeTextSpan>(),
-                        gfx::Range::InvalidRange(), 0);
+    rwh_helper_->ImeCommitText(text, std::vector<ImeTextSpan>(),
+                               gfx::Range::InvalidRange(), 0);
   }
-  rwhi->ImeFinishComposingText(false);
+  rwh_helper_->ImeFinishComposingText(false);
 }
 
 void IMContextEfl::SetSurroundingText(std::string value) {
index 7a6ad99..2fb8f8e 100644 (file)
@@ -23,8 +23,7 @@
 typedef struct _Ecore_IMF_Context Ecore_IMF_Context;
 
 namespace content {
-class RenderWidgetHostImpl;
-class RWHVAuraOffscreenHelperEfl;
+class RenderWidgetHostHelper;
 }  // namespace content
 
 namespace ui {
@@ -76,8 +75,9 @@ class IMContextEfl {
   void UpdateCaretBounds(const gfx::Rect& caret_bounds);
   bool IsShow();
 
-  void SetRWHVHelper(content::RWHVAuraOffscreenHelperEfl* rwhv_helper) {
-    rwhv_helper_ = rwhv_helper;
+  // To forward RenderWidgetHostImpl calls.
+  void SetRWHHelper(content::RenderWidgetHostHelper* rwh_helper) {
+    rwh_helper_ = rwh_helper;
   }
 
 #if BUILDFLAG(IS_TIZEN_TV)
@@ -167,7 +167,7 @@ class IMContextEfl {
   void ProcessNextPreeditText(bool processed);
   void ProcessNextKeyDownEvent();
   void ProcessNextKeyUpEvent();
-  content::RenderWidgetHostImpl* GetRenderWidgetHostImpl() const;
+  bool HasRenderWidgetHostImpl() const;
 
   void SendFakeCompositionKeyEvent(const std::u16string& buf);
 
@@ -213,7 +213,7 @@ class IMContextEfl {
   bool is_keyevent_processing_ = false;
   bool is_transaction_finished_ = true;
   InputMethodAuraLinux* im_aura_ = nullptr;
-  content::RWHVAuraOffscreenHelperEfl* rwhv_helper_ = nullptr;
+  content::RenderWidgetHostHelper* rwh_helper_ = nullptr;
 };
 
 }  // namespace ui