Bug 748384 - Propagate the page bounds in via browser.js. r=Cwiiis,mats

This commit is contained in:
Kartikaya Gupta 2012-05-23 10:49:59 -04:00
Родитель c3897ce9b5
Коммит 178a609009
4 изменённых файлов: 79 добавлений и 32 удалений

Просмотреть файл

@ -49,6 +49,7 @@
#include "nsIDocShell.h"
#include "nsIContentViewer.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsClientRect.h"
#if defined(MOZ_X11) && defined(MOZ_WIDGET_GTK2)
#include <gdk/gdk.h>
@ -1260,6 +1261,39 @@ nsDOMWindowUtils::GetScrollXY(bool aFlushLayout, PRInt32* aScrollX, PRInt32* aSc
return NS_OK;
}
NS_IMETHODIMP
nsDOMWindowUtils::GetRootBounds(nsIDOMClientRect** aResult)
{
// Weak ref, since we addref it below
nsClientRect* rect = new nsClientRect();
NS_ADDREF(*aResult = rect);
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
NS_ENSURE_STATE(window);
nsCOMPtr<nsIDocument> doc(do_QueryInterface(window->GetExtantDocument()));
NS_ENSURE_STATE(doc);
nsRect bounds(0, 0, 0, 0);
nsIPresShell* presShell = doc->GetShell();
if (presShell) {
nsIScrollableFrame* sf = presShell->GetRootScrollFrameAsScrollable();
if (sf) {
bounds = sf->GetScrollRange();
bounds.width += sf->GetScrollPortRect().width;
bounds.height += sf->GetScrollPortRect().height;
} else if (presShell->GetRootFrame()) {
bounds = presShell->GetRootFrame()->GetRect();
}
}
rect->SetRect(nsPresContext::AppUnitsToFloatCSSPixels(bounds.x),
nsPresContext::AppUnitsToFloatCSSPixels(bounds.y),
nsPresContext::AppUnitsToFloatCSSPixels(bounds.width),
nsPresContext::AppUnitsToFloatCSSPixels(bounds.height));
return NS_OK;
}
NS_IMETHODIMP
nsDOMWindowUtils::GetIMEIsOpen(bool *aState)
{

Просмотреть файл

@ -37,8 +37,9 @@ interface nsIDOMBlob;
interface nsIDOMFile;
interface nsIFile;
interface nsIDOMTouch;
interface nsIDOMClientRect;
[scriptable, uuid(2e5a1f37-786b-4a52-b0e3-f711ee2268a8)]
[scriptable, uuid(2b3ac53c-2a88-421f-af09-f10665c88acf)]
interface nsIDOMWindowUtils : nsISupports {
/**
@ -594,6 +595,13 @@ interface nsIDOMWindowUtils : nsISupports {
*/
void getScrollXY(in boolean aFlushLayout, out long aScrollX, out long aScrollY);
/**
* Returns the bounds of the window's currently loaded document. This will
* generally be (0, 0, pageWidth, pageHeight) but in some cases (e.g. RTL
* documents) may have a negative left value.
*/
nsIDOMClientRect getRootBounds();
/**
* Get IME open state. TRUE means 'Open', otherwise, 'Close'.
* This property works only when IMEEnabled is IME_STATUS_ENABLED.

Просмотреть файл

@ -70,14 +70,14 @@ public class ViewportMetrics {
float y = (float)json.getDouble("y");
float width = (float)json.getDouble("width");
float height = (float)json.getDouble("height");
float pageLeft = 0.0f;
float pageTop = 0.0f;
float pageRight = (float)json.getDouble("pageWidth");
float pageBottom = (float)json.getDouble("pageHeight");
float cssPageLeft = 0.0f;
float cssPageTop = 0.0f;
float cssPageRight = (float)json.getDouble("cssPageWidth");
float cssPageBottom = (float)json.getDouble("cssPageHeight");
float pageLeft = (float)json.getDouble("pageLeft");
float pageTop = (float)json.getDouble("pageTop");
float pageRight = (float)json.getDouble("pageRight");
float pageBottom = (float)json.getDouble("pageBottom");
float cssPageLeft = (float)json.getDouble("cssPageLeft");
float cssPageTop = (float)json.getDouble("cssPageTop");
float cssPageRight = (float)json.getDouble("cssPageRight");
float cssPageBottom = (float)json.getDouble("cssPageBottom");
float zoom = (float)json.getDouble("zoom");
mPageRect = new RectF(pageLeft, pageTop, pageRight, pageBottom);

Просмотреть файл

@ -1871,11 +1871,15 @@ Tab.prototype = {
height: gScreenHeight,
cssWidth: gScreenWidth / this._zoom,
cssHeight: gScreenHeight / this._zoom,
pageWidth: gScreenWidth,
pageHeight: gScreenHeight,
pageLeft: 0,
pageTop: 0,
pageRight: gScreenWidth,
pageBottom: gScreenHeight,
// We make up matching css page dimensions
cssPageWidth: gScreenWidth / this._zoom,
cssPageHeight: gScreenHeight / this._zoom,
cssPageLeft: 0,
cssPageTop: 0,
cssPageRight: gScreenWidth / this._zoom,
cssPageBottom: gScreenHeight / this._zoom,
zoom: this._zoom,
};
@ -1889,30 +1893,31 @@ Tab.prototype = {
let doc = this.browser.contentDocument;
if (doc != null) {
let [pageWidth, pageHeight] = this.getPageSize(doc, viewport.cssWidth, viewport.cssHeight);
let cssPageWidth = pageWidth;
let cssPageHeight = pageHeight;
/* Transform the page width and height based on the zoom factor. */
pageWidth *= viewport.zoom;
pageHeight *= viewport.zoom;
let cwu = this.browser.contentWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
let cssPageRect = cwu.getRootBounds();
/*
* Avoid sending page sizes of less than screen size before we hit DOMContentLoaded, because
* this causes the page size to jump around wildly during page load. After the page is loaded,
* send updates regardless of page size; we'll zoom to fit the content as needed.
*
* Also, we need to compare the page size returned from getPageSize (in CSS pixels) to the floored
* screen size in CSS pixels because the page size returned from getPageSize may also be floored.
* In the check below, we floor the viewport size because there might be slight rounding errors
* introduced in the CSS page size due to the conversion to and from app units in Gecko. The
* error should be no more than one app unit so doing the floor is overkill, but safe in the
* sense that the extra page size updates that get sent as a result will be mostly harmless.
*/
let pageLargerThanScreen = (cssPageWidth >= Math.floor(viewport.cssWidth))
&& (cssPageHeight >= Math.floor(viewport.cssHeight));
let pageLargerThanScreen = (cssPageRect.width >= Math.floor(viewport.cssWidth))
&& (cssPageRect.height >= Math.floor(viewport.cssHeight));
if (doc.readyState === 'complete' || pageLargerThanScreen) {
viewport.cssPageWidth = cssPageWidth;
viewport.cssPageHeight = cssPageHeight;
viewport.pageWidth = pageWidth;
viewport.pageHeight = pageHeight;
viewport.cssPageLeft = cssPageRect.left;
viewport.cssPageTop = cssPageRect.top;
viewport.cssPageRight = cssPageRect.right;
viewport.cssPageBottom = cssPageRect.bottom;
/* Transform the page width and height based on the zoom factor. */
viewport.pageLeft = (viewport.cssPageLeft * viewport.zoom);
viewport.pageTop = (viewport.cssPageTop * viewport.zoom);
viewport.pageRight = (viewport.cssPageRight * viewport.zoom);
viewport.pageBottom = (viewport.cssPageBottom * viewport.zoom);
}
}
@ -2695,13 +2700,13 @@ var BrowserEventHandler = {
let viewport = BrowserApp.selectedTab.getViewport();
let vRect = new Rect(viewport.cssX, viewport.cssY, viewport.cssWidth, viewport.cssHeight);
let bRect = new Rect(Math.max(0,rect.x - margin),
let bRect = new Rect(Math.max(viewport.cssPageLeft, rect.x - margin),
rect.y,
rect.w + 2*margin,
rect.h);
// constrict the rect to the screen width
bRect.width = Math.min(bRect.width, viewport.cssPageWidth - bRect.x);
// constrict the rect to the screen's right edge
bRect.width = Math.min(bRect.width, viewport.cssPageRight - bRect.x);
let overlap = vRect.intersect(bRect);
let overlapArea = overlap.width*overlap.height;