#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();
}
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";
namespace content {
+class RenderWidgetHostHelper;
class RenderWidgetHostImpl;
class RenderWidgetHostViewAura;
class WebContents;
ui::IMContextEfl* im_context_efl_ = nullptr;
RenderWidgetHostViewAura* rwhv_aura_ = nullptr;
WebContents* web_contents_ = nullptr;
+
+ std::unique_ptr<RenderWidgetHostHelper> rwh_helper_;
};
} // namespace content
--- /dev/null
+// 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_
#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"
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);
}
}
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);
}
}
}
void IMContextEfl::OnDeleteSurrounding(void* event_info) {
- auto rwhi = GetRenderWidgetHostImpl();
- if (!rwhi) {
+ if (!HasRenderWidgetHostImpl()) {
LOG(ERROR) << "rwhi is nullptr";
return;
}
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;
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();
}
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() {
// 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";
}
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) {
typedef struct _Ecore_IMF_Context Ecore_IMF_Context;
namespace content {
-class RenderWidgetHostImpl;
-class RWHVAuraOffscreenHelperEfl;
+class RenderWidgetHostHelper;
} // namespace content
namespace ui {
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)
void ProcessNextPreeditText(bool processed);
void ProcessNextKeyDownEvent();
void ProcessNextKeyUpEvent();
- content::RenderWidgetHostImpl* GetRenderWidgetHostImpl() const;
+ bool HasRenderWidgetHostImpl() const;
void SendFakeCompositionKeyEvent(const std::u16string& buf);
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