[pdf] IME menu positioning
Pass the caret position to Pepper so that the IME menu can be displayed at the proper position. The menu was displayed at the bottom of the viewport. After this fix, it will be displayed below the focused editable form control. Bug: 601322 Change-Id: I1fdbe626b63575038ddb7990bb7f77eb19af8b64 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3043885 Commit-Queue: Keren Zhu <kerenzhu@chromium.org> Reviewed-by: Bill Budge <bbudge@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Cr-Commit-Position: refs/heads/master@{#904089}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
24b16b8c40
commit
7287af73bf
content/renderer/pepper
pdf
@ -1028,11 +1028,6 @@ gfx::Rect PepperPluginInstanceImpl::GetCaretBounds() const {
|
||||
}
|
||||
|
||||
// TODO(kinaba) Take CSS transformation into account.
|
||||
// TODO(kinaba) Take |text_input_caret_info_->caret_bounds| into account. On
|
||||
// some platforms, an "exclude rectangle" where candidate window must avoid
|
||||
// the region can be passed to IME. Currently, we pass only the caret
|
||||
// rectangle because it is the only information supported uniformly in
|
||||
// Chromium.
|
||||
gfx::Rect caret = text_input_caret_info_->caret;
|
||||
caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y);
|
||||
ConvertDIPToViewport(&caret);
|
||||
|
@ -783,6 +783,12 @@ void OutOfProcessInstance::NotifySelectedFindResultChanged(
|
||||
SelectedFindResultChanged(current_find_index);
|
||||
}
|
||||
|
||||
void OutOfProcessInstance::CaretChanged(const gfx::Rect& caret_rect) {
|
||||
PP_Rect caret_viewport =
|
||||
PPRectFromRect(caret_rect + available_area().OffsetFromOrigin());
|
||||
text_input_->UpdateCaretPosition(caret_viewport, caret_viewport);
|
||||
}
|
||||
|
||||
void OutOfProcessInstance::Alert(const std::string& message) {
|
||||
pp::PDF::ShowAlertDialog(this, message.c_str());
|
||||
}
|
||||
|
@ -92,6 +92,7 @@ class OutOfProcessInstance : public PdfViewPluginBase,
|
||||
void UpdateTickMarks(const std::vector<gfx::Rect>& tickmarks) override;
|
||||
void NotifyNumberOfFindResultsChanged(int total, bool final_result) override;
|
||||
void NotifySelectedFindResultChanged(int current_find_index) override;
|
||||
void CaretChanged(const gfx::Rect& caret_rect) override;
|
||||
void Alert(const std::string& message) override;
|
||||
bool Confirm(const std::string& message) override;
|
||||
std::string Prompt(const std::string& question,
|
||||
|
@ -269,6 +269,9 @@ class PDFEngine {
|
||||
virtual void SelectionChanged(const gfx::Rect& left,
|
||||
const gfx::Rect& right) {}
|
||||
|
||||
// The caret position in the editable form (if applicable) changed.
|
||||
virtual void CaretChanged(const gfx::Rect& caret_rect) {}
|
||||
|
||||
// Notifies the client that the PDF has been edited.
|
||||
virtual void EnteredEditMode() {}
|
||||
|
||||
|
@ -606,7 +606,12 @@ void PDFiumEngine::ScrolledToXPosition(int position) {
|
||||
int old_x = position_.x();
|
||||
position_.set_x(position);
|
||||
CalculateVisiblePages();
|
||||
client_->DidScroll(gfx::Vector2d(old_x - position, 0));
|
||||
|
||||
gfx::Vector2d diff(position - old_x, 0);
|
||||
client_->DidScroll(-diff);
|
||||
caret_rect_ += diff;
|
||||
client_->CaretChanged(caret_rect_);
|
||||
|
||||
OnSelectionPositionChanged();
|
||||
}
|
||||
|
||||
@ -616,7 +621,12 @@ void PDFiumEngine::ScrolledToYPosition(int position) {
|
||||
int old_y = position_.y();
|
||||
position_.set_y(position);
|
||||
CalculateVisiblePages();
|
||||
client_->DidScroll(gfx::Vector2d(0, old_y - position));
|
||||
|
||||
gfx::Vector2d diff(0, position - old_y);
|
||||
client_->DidScroll(-diff);
|
||||
caret_rect_ += diff;
|
||||
client_->CaretChanged(caret_rect_);
|
||||
|
||||
OnSelectionPositionChanged();
|
||||
}
|
||||
|
||||
@ -3918,6 +3928,25 @@ void PDFiumEngine::OnFocusedAnnotationUpdated(FPDF_ANNOTATION annot,
|
||||
SetInFormTextArea(is_form_text_area);
|
||||
editable_form_text_area_ =
|
||||
is_form_text_area && IsAnnotationAnEditableFormTextArea(annot, form_type);
|
||||
|
||||
if (editable_form_text_area_ && PageIndexInBounds(page_index)) {
|
||||
FS_RECTF annot_rect;
|
||||
if (!FPDFAnnot_GetRect(annot, &annot_rect))
|
||||
return;
|
||||
|
||||
// Position assuming top-left of the first page is at (0,0).
|
||||
gfx::Rect rect_screen = pages_[page_index]->PageToScreen(
|
||||
gfx::Point(), current_zoom_, annot_rect.left, annot_rect.top,
|
||||
annot_rect.right, annot_rect.bottom,
|
||||
layout_.options().default_page_orientation());
|
||||
|
||||
// Position in viewport.
|
||||
caret_rect_.SetRect(rect_screen.x() - position_.x(),
|
||||
rect_screen.y() - position_.y(), rect_screen.width(),
|
||||
rect_screen.height());
|
||||
|
||||
client_->CaretChanged(caret_rect_);
|
||||
}
|
||||
}
|
||||
|
||||
void PDFiumEngine::SetCaretPosition(const gfx::Point& position) {
|
||||
|
@ -650,6 +650,8 @@ class PDFiumEngine : public PDFEngine,
|
||||
// The plugin size in screen coordinates.
|
||||
gfx::Size plugin_size_;
|
||||
double current_zoom_ = 1.0;
|
||||
// The caret position and bound in plugin viewport coordinates.
|
||||
gfx::Rect caret_rect_;
|
||||
|
||||
std::unique_ptr<DocumentLoader> doc_loader_; // Main document's loader.
|
||||
bool doc_loader_set_for_testing_ = false;
|
||||
|
Reference in New Issue
Block a user