// for snapshot
frame_rendered_ = true;
+
+ // Get snapshot for magnifier.
+ if (!magnifier_snapshot_request_.is_null()) {
+ std::move(magnifier_snapshot_request_).Run();
+ magnifier_snapshot_request_.Reset();
+ }
}
void RWHVAuraOffscreenHelperEfl::InitEvasGL() {
blink::WebGestureEvent& event) {
HandleGesture(event);
blink::WebInputEvent::Type event_type = event.GetType();
- if (event_type == blink::WebInputEvent::Type::kGestureScrollUpdate)
+ if (magnifier_ &&
+ event_type == blink::WebInputEvent::Type::kGestureScrollUpdate) {
return;
+ }
if (event_type != blink::WebInputEvent::Type::kUndefined) {
rwhv_aura_->host()->ForwardGestureEventWithLatencyInfo(
}
}
+void RWHVAuraOffscreenHelperEfl::set_magnifier(bool status) {
+ magnifier_ = status;
+}
+
+void RWHVAuraOffscreenHelperEfl::GetMagnifierSnapshot(
+ gfx::Rect snapshot_area,
+ float scale_factor,
+ std::unique_ptr<ScreenshotCapturedCallback> cb) {
+#if defined(USE_TTRACE)
+ TTRACE(TTRACE_TAG_WEB,
+ "RenderWidgetHostViewAuraHelperEfl::GetMagnifierSnapshot");
+#endif
+ // GetSnapshot might be replaced with something designed for magnifier.
+ Evas_Object* image = GetSnapshot(snapshot_area, scale_factor, true);
+
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE,
+ base::BindOnce(&ScreenshotCapturedCallback::Run,
+ base::Owned(cb.release()), base::Unretained(image)));
+}
+
+void RWHVAuraOffscreenHelperEfl::RequestMagnifierSnapshotAsync(
+ const Eina_Rectangle rect,
+ Screenshot_Captured_Callback callback,
+ void* user_data,
+ float scale_factor) {
+ gfx::Rect snapshot_area(rect.x, rect.y, rect.w, rect.h);
+ gfx::Rect view_rect = GetViewBoundsInPix();
+
+ // Adjust snapshot rect for email app
+ auto visible_viewport_rect = selection_controller_->GetVisibleViewportRect();
+ int hidden_view_width = visible_viewport_rect.x() - view_rect.x();
+ int hidden_view_height = visible_viewport_rect.y() - view_rect.y();
+ if (hidden_view_height || hidden_view_width) {
+ snapshot_area.set_x(snapshot_area.x() + hidden_view_width);
+ snapshot_area.set_y(snapshot_area.y() + hidden_view_height);
+ }
+
+ magnifier_snapshot_request_ =
+ base::BindOnce(&RWHVAuraOffscreenHelperEfl::GetMagnifierSnapshot,
+ base::Unretained(this), snapshot_area, scale_factor,
+ std::move(std::unique_ptr<ScreenshotCapturedCallback>(
+ new ScreenshotCapturedCallback(callback, user_data))));
+}
+
void RWHVAuraOffscreenHelperEfl::HandleGesture(blink::WebGestureEvent& event) {
SelectionControllerEfl* controller = GetSelectionController();
if (controller)
evas_object_del(container_);
}
-void SelectionMagnifierEfl::HandleLongPress(const gfx::Point& touch_point) {
+void SelectionMagnifierEfl::HandleLongPress(const gfx::Point& touch_point,
+ bool is_in_edit_field) {
evas_object_event_callback_add(
controller_->rwhva()->offscreen_helper()->content_image(),
EVAS_CALLBACK_MOUSE_MOVE, OnAnimatorMove, this);
// Call OnAnimatorMove here, so that the magnifier widget
// gets properly placed. Other calls to it are expected to
// happen as a react to finger/mouse movements.
- OnAnimatorMove();
- Show();
+ if (!is_in_edit_field && !controller_->HandleBeingDragged()) {
+ OnAnimatorMove();
+ Show();
+ }
}
void SelectionMagnifierEfl::DisconnectCallbacks() {
EVAS_CALLBACK_MOUSE_UP, OnAnimatorUp);
}
-void SelectionMagnifierEfl::OnAnimatorMove(void* data, Evas*, Evas_Object*, void*) {
- SelectionMagnifierEfl* magnifier_data = static_cast<SelectionMagnifierEfl*>(data);
+void SelectionMagnifierEfl::OnAnimatorMove(void* data,
+ Evas*,
+ Evas_Object*,
+ void*) {
+ auto* magnifier_data = static_cast<SelectionMagnifierEfl*>(data);
DCHECK(magnifier_data);
if (magnifier_data)
&point.x, &point.y);
gfx::Point display_point(point.x, point.y);
controller_->HandleLongPressMoveEvent(display_point);
- UpdateLocation(display_point);
- Move(display_point);
+
+ if (controller_->GetVisibleViewportRect().Contains(display_point)) {
+ UpdateLocation(display_point);
+ Move(display_point);
+ }
}
-void SelectionMagnifierEfl::OnAnimatorUp(void* data, Evas*, Evas_Object*, void*) {
- SelectionMagnifierEfl* magnifier_data = static_cast<SelectionMagnifierEfl*>(data);
+void SelectionMagnifierEfl::OnAnimatorUp(void* data,
+ Evas*,
+ Evas_Object*,
+ void*) {
+ auto* magnifier_data = static_cast<SelectionMagnifierEfl*>(data);
DCHECK(magnifier_data);
if (magnifier_data)
}
void SelectionMagnifierEfl::MagnifierGetSnapshotCb(Evas_Object* image,
- void* user_data)
-{
- SelectionMagnifierEfl* selection_magnifier =
- static_cast<SelectionMagnifierEfl*>(user_data);
+ void* user_data) {
+ auto* selection_magnifier = static_cast<SelectionMagnifierEfl*>(user_data);
if (selection_magnifier->content_image_) {
evas_object_del(selection_magnifier->content_image_);
selection_magnifier->content_image_ = image;
evas_object_show(selection_magnifier->content_image_);
- elm_object_part_content_set(selection_magnifier->container_,
- "swallow", selection_magnifier->content_image_);
+ elm_object_part_content_set(selection_magnifier->container_, "swallow",
+ selection_magnifier->content_image_);
evas_object_pass_events_set(selection_magnifier->content_image_, EINA_TRUE);
evas_object_clip_set(selection_magnifier->content_image_,
selection_magnifier->container_);
}
void SelectionMagnifierEfl::UpdateLocation(const gfx::Point& location) {
- int device_x, device_y, device_width, device_height;
- evas_object_geometry_get(
- controller_->rwhva()->offscreen_helper()->content_image(), &device_x,
- &device_y, &device_width, &device_height);
+ auto visible_viewport_rect = controller_->GetVisibleViewportRect();
+ int visible_viewport_x = visible_viewport_rect.x();
+ int visible_viewport_y = visible_viewport_rect.y();
+ int visible_viewport_width = visible_viewport_rect.width();
+ int visible_viewport_height = visible_viewport_rect.height();
int zoomedWidth = width_ * kZoomScale;
int zoomedHeight = height_ * kZoomScale;
- if (zoomedWidth > device_width)
- zoomedWidth = device_width;
+ if (zoomedWidth > visible_viewport_width)
+ zoomedWidth = visible_viewport_width;
- if (zoomedHeight > device_height)
- zoomedHeight = device_height;
+ if (zoomedHeight > visible_viewport_height)
+ zoomedHeight = visible_viewport_height;
- gfx::Rect content_rect(location.x() - zoomedWidth/2,
- location.y() - zoomedHeight/2, zoomedWidth, zoomedHeight);
+ // Place screenshot area center on touch point
+ gfx::Rect content_rect(location.x() - zoomedWidth / 2,
+ location.y() - zoomedHeight / 2, zoomedWidth,
+ zoomedHeight);
- // Adjustments for boundry conditions
- if (content_rect.x() < device_x)
- content_rect.set_x(device_x);
- else if ((content_rect.x() + zoomedWidth) > device_x + device_width)
- content_rect.set_x(device_x + device_width - zoomedWidth);
+ // Move magnifier rect so it stays inside webview area
+ if (content_rect.x() < visible_viewport_x) {
+ content_rect.set_x(visible_viewport_x);
+ } else if ((content_rect.x() + zoomedWidth) >=
+ visible_viewport_x + visible_viewport_width) {
+ content_rect.set_x(visible_viewport_x + visible_viewport_width -
+ zoomedWidth - 1);
+ }
- if (content_rect.y() < device_y) // Do not let location to be less then magnifier y value
- content_rect.set_y(device_y);
- else if (content_rect.y() > device_y + device_height - zoomedHeight)
- content_rect.set_y(device_y + device_height - zoomedHeight);
+ if (content_rect.y() < visible_viewport_y) {
+ content_rect.set_y(visible_viewport_y);
+ } else if ((content_rect.y() + zoomedHeight) >=
+ visible_viewport_y + visible_viewport_height) {
+ content_rect.set_y(visible_viewport_y + visible_viewport_height -
+ zoomedHeight - 1);
+ }
+ // Convert to webview parameter space
Eina_Rectangle rect;
- rect.x = content_rect.x();
- rect.y = content_rect.y();
+ rect.x = content_rect.x() - visible_viewport_x;
+ rect.y = content_rect.y() - visible_viewport_y;
rect.w = content_rect.width();
rect.h = content_rect.height();
-#if !defined(USE_AURA)
- RenderWidgetHostViewEfl* rwhv =
- static_cast<RenderWidgetHostViewEfl*>(web_contents_.GetRenderWidgetHostView());
- if (rwhv)
- rwhv->RequestSnapshotAsync(rect, MagnifierGetSnapshotCb, this);
-#endif
+
+ controller_->rwhva()->offscreen_helper()->RequestMagnifierSnapshotAsync(
+ rect, MagnifierGetSnapshotCb, this);
}
void SelectionMagnifierEfl::Move(const gfx::Point& location) {
- int device_x, device_y, device_width, device_height;
- evas_object_geometry_get(
- controller_->rwhva()->offscreen_helper()->content_image(), &device_x,
- &device_y, &device_width, &device_height);
+ auto visible_viewport_rect = controller_->GetVisibleViewportRect();
+ int visible_viewport_x = visible_viewport_rect.x();
+ int visible_viewport_y = visible_viewport_rect.y();
+ int visible_viewport_width = visible_viewport_rect.width();
+ int visible_viewport_height = visible_viewport_rect.height();
int magnifier_x = location.x();
int magnifier_y = location.y() - height_ - kHeightOffset;
- if (magnifier_y < device_y) // Do not let location to be out of screen
- magnifier_y = device_y;
- else if (magnifier_y > device_height + device_y - height_)
- magnifier_y = device_height + device_y - height_;
-
- if (magnifier_x < device_x + width_/2) // Do not let location to be out of screen
- magnifier_x = device_x + width_/2;
- else if (magnifier_x > device_width + device_x - width_/2)
- magnifier_x = device_width + device_x - width_/2;
+ // Do not let location to be out of screen
+ if (magnifier_y < visible_viewport_y) {
+ magnifier_y = visible_viewport_y;
+ } else if (magnifier_y >
+ visible_viewport_height + visible_viewport_y - height_) {
+ magnifier_y = visible_viewport_height + visible_viewport_y - height_;
+ }
+ // Do not let location to be out of screen
+ if (magnifier_x < visible_viewport_x + width_ / 2) {
+ magnifier_x = visible_viewport_x + width_ / 2;
+ } else if (magnifier_x >
+ visible_viewport_width + visible_viewport_x - width_ / 2) {
+ magnifier_x = visible_viewport_width + visible_viewport_x - width_ / 2;
+ }
evas_object_move(container_, magnifier_x, magnifier_y);
}
shown_ = true;
evas_object_show(container_);
-#if !defined(USE_AURA)
- RenderWidgetHostViewEfl* rwhv =
- static_cast<RenderWidgetHostViewEfl*>(web_contents_.GetRenderWidgetHostView());
- if (rwhv)
- rwhv->set_magnifier(true);
-#endif
+ controller_->rwhva()->offscreen_helper()->set_magnifier(true);
if (controller_->rwhva()->offscreen_helper()->ewk_view()) {
evas_object_smart_callback_call(
controller_->rwhva()->offscreen_helper()->ewk_view(), "magnifier,show",
}
void SelectionMagnifierEfl::Hide() {
+ if (!shown_)
+ return;
+
shown_ = false;
evas_object_hide(content_image_);
evas_object_hide(container_);
-#if !defined(USE_AURA)
- RenderWidgetHostViewEfl* rwhv =
- static_cast<RenderWidgetHostViewEfl*>(web_contents_.GetRenderWidgetHostView());
- if (rwhv)
- rwhv->set_magnifier(false);
-#endif
+ controller_->rwhva()->offscreen_helper()->set_magnifier(false);
if (controller_->rwhva()->offscreen_helper()->ewk_view()) {
evas_object_smart_callback_call(
controller_->rwhva()->offscreen_helper()->ewk_view(), "magnifier,hide",