Commit 68aa2ca1 authored by calamity@chromium.org's avatar calamity@chromium.org

Make 1.5x DPI text render crisply.

This CL fixes an issue where the text would render blurrily on 1.5x DPI
screens. This was caused by WebContentsView::OnBoundsChanged() not
getting called because the origin is no longer changed when switching the
active tab as it is always inside the clipping window. This is fixed
by calling SnapToPhysicalPixelBoundary() when the clipping window gets
a new WebContents set.

BUG=388908

Review URL: https://codereview.chromium.org/366543004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282583 0039d316-1c4b-4281-b951-d872f2087c98
parent 209ddd29
......@@ -968,78 +968,6 @@ void RenderWidgetHostViewAura::AcceleratedSurfaceInitialized(int host_id,
int route_id) {
}
void RenderWidgetHostViewAura::SnapToPhysicalPixelBoundary() {
// The top left corner of our view in window coordinates might not land on a
// device pixel boundary if we have a non-integer device scale. In that case,
// to avoid the web contents area looking blurry we translate the web contents
// in the +x, +y direction to land on the nearest pixel boundary. This may
// cause the bottom and right edges to be clipped slightly, but that's ok.
gfx::Point view_offset_dips = window_->GetBoundsInRootWindow().origin();
gfx::PointF view_offset = view_offset_dips;
view_offset.Scale(current_device_scale_factor_);
gfx::PointF view_offset_snapped(std::ceil(view_offset.x()),
std::ceil(view_offset.y()));
gfx::Vector2dF fudge = view_offset_snapped - view_offset;
fudge.Scale(1.0 / current_device_scale_factor_);
GetLayer()->SetSubpixelPositionOffset(fudge);
}
void RenderWidgetHostViewAura::InternalSetBounds(const gfx::Rect& rect) {
if (HasDisplayPropertyChanged(window_))
host_->InvalidateScreenInfo();
SnapToPhysicalPixelBoundary();
// Don't recursively call SetBounds if this bounds update is the result of
// a Window::SetBoundsInternal call.
if (!in_bounds_changed_)
window_->SetBounds(rect);
host_->WasResized();
delegated_frame_host_->WasResized();
if (touch_editing_client_) {
touch_editing_client_->OnSelectionOrCursorChanged(selection_anchor_rect_,
selection_focus_rect_);
}
#if defined(OS_WIN)
// Create the legacy dummy window which corresponds to the bounds of the
// webcontents. This will be passed as the container window for windowless
// plugins.
// Plugins like Flash assume the container window which is returned via the
// NPNVnetscapeWindow property corresponds to the bounds of the webpage.
// This is not true in Aura where we have only HWND which is the main Aura
// window. If we return this window to plugins like Flash then it causes the
// coordinate translations done by these plugins to break.
// Additonally the legacy dummy window is needed for accessibility and for
// scrolling to work in legacy drivers for trackpoints/trackpads, etc.
if (!legacy_window_destroyed_ && GetNativeViewId()) {
if (!legacy_render_widget_host_HWND_) {
legacy_render_widget_host_HWND_ = LegacyRenderWidgetHostHWND::Create(
reinterpret_cast<HWND>(GetNativeViewId()));
}
if (legacy_render_widget_host_HWND_) {
legacy_render_widget_host_HWND_->set_host(this);
legacy_render_widget_host_HWND_->SetBounds(
window_->GetBoundsInRootWindow());
// There are cases where the parent window is created, made visible and
// the associated RenderWidget is also visible before the
// LegacyRenderWidgetHostHWND instace is created. Ensure that it is shown
// here.
if (!host_->is_hidden())
legacy_render_widget_host_HWND_->Show();
BrowserAccessibilityManagerWin* manager =
static_cast<BrowserAccessibilityManagerWin*>(
GetBrowserAccessibilityManager());
if (manager)
manager->SetAccessibleHWND(legacy_render_widget_host_HWND_);
}
}
if (mouse_locked_)
UpdateMouseLockRegion();
#endif
}
#if defined(OS_WIN)
bool RenderWidgetHostViewAura::UsesNativeWindowFrame() const {
return (legacy_render_widget_host_HWND_ != NULL);
......@@ -2314,6 +2242,78 @@ void RenderWidgetHostViewAura::SetOverscrollControllerEnabled(bool enabled) {
overscroll_controller_.reset(new OverscrollController());
}
void RenderWidgetHostViewAura::SnapToPhysicalPixelBoundary() {
// The top left corner of our view in window coordinates might not land on a
// device pixel boundary if we have a non-integer device scale. In that case,
// to avoid the web contents area looking blurry we translate the web contents
// in the +x, +y direction to land on the nearest pixel boundary. This may
// cause the bottom and right edges to be clipped slightly, but that's ok.
gfx::Point view_offset_dips = window_->GetBoundsInRootWindow().origin();
gfx::PointF view_offset = view_offset_dips;
view_offset.Scale(current_device_scale_factor_);
gfx::PointF view_offset_snapped(std::ceil(view_offset.x()),
std::ceil(view_offset.y()));
gfx::Vector2dF fudge = view_offset_snapped - view_offset;
fudge.Scale(1.0 / current_device_scale_factor_);
GetLayer()->SetSubpixelPositionOffset(fudge);
}
void RenderWidgetHostViewAura::InternalSetBounds(const gfx::Rect& rect) {
if (HasDisplayPropertyChanged(window_))
host_->InvalidateScreenInfo();
SnapToPhysicalPixelBoundary();
// Don't recursively call SetBounds if this bounds update is the result of
// a Window::SetBoundsInternal call.
if (!in_bounds_changed_)
window_->SetBounds(rect);
host_->WasResized();
delegated_frame_host_->WasResized();
if (touch_editing_client_) {
touch_editing_client_->OnSelectionOrCursorChanged(selection_anchor_rect_,
selection_focus_rect_);
}
#if defined(OS_WIN)
// Create the legacy dummy window which corresponds to the bounds of the
// webcontents. This will be passed as the container window for windowless
// plugins.
// Plugins like Flash assume the container window which is returned via the
// NPNVnetscapeWindow property corresponds to the bounds of the webpage.
// This is not true in Aura where we have only HWND which is the main Aura
// window. If we return this window to plugins like Flash then it causes the
// coordinate translations done by these plugins to break.
// Additonally the legacy dummy window is needed for accessibility and for
// scrolling to work in legacy drivers for trackpoints/trackpads, etc.
if (!legacy_window_destroyed_ && GetNativeViewId()) {
if (!legacy_render_widget_host_HWND_) {
legacy_render_widget_host_HWND_ = LegacyRenderWidgetHostHWND::Create(
reinterpret_cast<HWND>(GetNativeViewId()));
}
if (legacy_render_widget_host_HWND_) {
legacy_render_widget_host_HWND_->set_host(this);
legacy_render_widget_host_HWND_->SetBounds(
window_->GetBoundsInRootWindow());
// There are cases where the parent window is created, made visible and
// the associated RenderWidget is also visible before the
// LegacyRenderWidgetHostHWND instace is created. Ensure that it is shown
// here.
if (!host_->is_hidden())
legacy_render_widget_host_HWND_->Show();
BrowserAccessibilityManagerWin* manager =
static_cast<BrowserAccessibilityManagerWin*>(
GetBrowserAccessibilityManager());
if (manager)
manager->SetAccessibleHWND(legacy_render_widget_host_HWND_);
}
}
if (mouse_locked_)
UpdateMouseLockRegion();
#endif
}
void RenderWidgetHostViewAura::SchedulePaintIfNotInClip(
const gfx::Rect& rect,
const gfx::Rect& clip) {
......
......@@ -336,6 +336,8 @@ class CONTENT_EXPORT RenderWidgetHostViewAura
// Sets whether the overscroll controller should be enabled for this page.
void SetOverscrollControllerEnabled(bool enabled);
void SnapToPhysicalPixelBoundary();
OverscrollController* overscroll_controller() const {
return overscroll_controller_.get();
}
......@@ -377,8 +379,6 @@ class CONTENT_EXPORT RenderWidgetHostViewAura
void UpdateCursorIfOverSelf();
void SnapToPhysicalPixelBoundary();
// Set the bounds of the window and handle size changes. Assumes the caller
// has already adjusted the origin of |rect| to conform to whatever coordinate
// space is required by the aura::Window.
......
......@@ -551,6 +551,12 @@ class WebContentsViewAura::WindowObserver
if (window != view_->window_)
return;
// Use the new parent's root window for calculating HiDPI subpixel offset.
RenderWidgetHostViewAura* rwhv = ToRenderWidgetHostViewAura(
view_->web_contents_->GetRenderWidgetHostView());
if (rwhv)
rwhv->SnapToPhysicalPixelBoundary();
aura::Window* host_window =
window->GetProperty(aura::client::kHostWindowKey);
if (!host_window)
......@@ -565,10 +571,8 @@ class WebContentsViewAura::WindowObserver
for (size_t i = 0; i < children.size(); ++i)
children[i]->RemoveObserver(this);
RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura(
view_->web_contents_->GetRenderWidgetHostView());
if (view)
view->UpdateConstrainedWindowRects(std::vector<gfx::Rect>());
if (rwhv)
rwhv->UpdateConstrainedWindowRects(std::vector<gfx::Rect>());
}
// When we get parented to the root window, the code below will watch the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment