| Index: third_party/google_input_tools/third_party/closure_library/closure/goog/positioning/positioning.js
|
| diff --git a/third_party/google_input_tools/third_party/closure_library/closure/goog/positioning/positioning.js b/third_party/google_input_tools/third_party/closure_library/closure/goog/positioning/positioning.js
|
| index 0d5c40c29a013da96df0d33ea768d2a5c06027cf..0097f2f0ce6151514016540e2a5aae55c1efc0e9 100644
|
| --- a/third_party/google_input_tools/third_party/closure_library/closure/goog/positioning/positioning.js
|
| +++ b/third_party/google_input_tools/third_party/closure_library/closure/goog/positioning/positioning.js
|
| @@ -15,6 +15,7 @@
|
| /**
|
| * @fileoverview Common positioning code.
|
| *
|
| + * @author eae@google.com (Emil A Eklund)
|
| */
|
|
|
| goog.provide('goog.positioning');
|
| @@ -26,8 +27,8 @@ goog.provide('goog.positioning.OverflowStatus');
|
| goog.require('goog.asserts');
|
| goog.require('goog.dom');
|
| goog.require('goog.dom.TagName');
|
| -goog.require('goog.math.Box');
|
| goog.require('goog.math.Coordinate');
|
| +goog.require('goog.math.Rect');
|
| goog.require('goog.math.Size');
|
| goog.require('goog.style');
|
| goog.require('goog.style.bidi');
|
| @@ -353,7 +354,6 @@ goog.positioning.positionAtCoordinate = function(absolutePos,
|
| opt_overflow,
|
| opt_preferredSize) {
|
| absolutePos = absolutePos.clone();
|
| - var status = goog.positioning.OverflowStatus.NONE;
|
|
|
| // Offset based on attached corner and desired margin.
|
| var corner = goog.positioning.getEffectiveCorner(movableElement,
|
| @@ -362,14 +362,66 @@ goog.positioning.positionAtCoordinate = function(absolutePos,
|
| var size = opt_preferredSize ? opt_preferredSize.clone() :
|
| elementSize.clone();
|
|
|
| - if (opt_margin || corner != goog.positioning.Corner.TOP_LEFT) {
|
| - if (corner & goog.positioning.CornerBit.RIGHT) {
|
| - absolutePos.x -= size.width + (opt_margin ? opt_margin.right : 0);
|
| + var positionResult = goog.positioning.getPositionAtCoordinate(absolutePos,
|
| + size, corner, opt_margin, opt_viewport, opt_overflow);
|
| +
|
| + if (positionResult.status & goog.positioning.OverflowStatus.FAILED) {
|
| + return positionResult.status;
|
| + }
|
| +
|
| + goog.style.setPosition(movableElement, positionResult.rect.getTopLeft());
|
| + size = positionResult.rect.getSize();
|
| + if (!goog.math.Size.equals(elementSize, size)) {
|
| + goog.style.setBorderBoxSize(movableElement, size);
|
| + }
|
| +
|
| + return positionResult.status;
|
| +};
|
| +
|
| +
|
| +/**
|
| + * Computes the position for an element to be placed on-screen at the
|
| + * specified coordinates. Returns an object containing both the resulting
|
| + * rectangle, and the overflow status bitmap.
|
| + *
|
| + * @param {!goog.math.Coordinate} absolutePos The coordinate to position the
|
| + * element at.
|
| + * @param {!goog.math.Size} elementSize The size of the element to be
|
| + * positioned.
|
| + * @param {goog.positioning.Corner} elementCorner The corner of the
|
| + * movableElement that that should be positioned.
|
| + * @param {goog.math.Box=} opt_margin A margin specified in pixels.
|
| + * After the normal positioning algorithm is applied and any offset, the
|
| + * margin is then applied. Positive coordinates move the popup away from the
|
| + * spot it was positioned towards its center. Negative coordinates move it
|
| + * towards the spot it was positioned away from its center.
|
| + * @param {goog.math.Box=} opt_viewport Box object describing the dimensions of
|
| + * the viewport. Required if opt_overflow is specified.
|
| + * @param {?number=} opt_overflow Overflow handling mode. Defaults to IGNORE
|
| + * if not specified, {@see goog.positioning.Overflow}.
|
| + * @return {{rect:!goog.math.Rect, status:goog.positioning.OverflowStatus}}
|
| + * Object containing the computed position and status bitmap.
|
| + */
|
| +goog.positioning.getPositionAtCoordinate = function(
|
| + absolutePos,
|
| + elementSize,
|
| + elementCorner,
|
| + opt_margin,
|
| + opt_viewport,
|
| + opt_overflow) {
|
| + absolutePos = absolutePos.clone();
|
| + elementSize = elementSize.clone();
|
| + var status = goog.positioning.OverflowStatus.NONE;
|
| +
|
| + if (opt_margin || elementCorner != goog.positioning.Corner.TOP_LEFT) {
|
| + if (elementCorner & goog.positioning.CornerBit.RIGHT) {
|
| + absolutePos.x -= elementSize.width + (opt_margin ? opt_margin.right : 0);
|
| } else if (opt_margin) {
|
| absolutePos.x += opt_margin.left;
|
| }
|
| - if (corner & goog.positioning.CornerBit.BOTTOM) {
|
| - absolutePos.y -= size.height + (opt_margin ? opt_margin.bottom : 0);
|
| + if (elementCorner & goog.positioning.CornerBit.BOTTOM) {
|
| + absolutePos.y -= elementSize.height +
|
| + (opt_margin ? opt_margin.bottom : 0);
|
| } else if (opt_margin) {
|
| absolutePos.y += opt_margin.top;
|
| }
|
| @@ -379,19 +431,16 @@ goog.positioning.positionAtCoordinate = function(absolutePos,
|
| if (opt_overflow) {
|
| status = opt_viewport ?
|
| goog.positioning.adjustForViewport_(
|
| - absolutePos, size, opt_viewport, opt_overflow) :
|
| + absolutePos, elementSize, opt_viewport, opt_overflow) :
|
| goog.positioning.OverflowStatus.FAILED_OUTSIDE_VIEWPORT;
|
| - if (status & goog.positioning.OverflowStatus.FAILED) {
|
| - return status;
|
| - }
|
| }
|
|
|
| - goog.style.setPosition(movableElement, absolutePos);
|
| - if (!goog.math.Size.equals(elementSize, size)) {
|
| - goog.style.setBorderBoxSize(movableElement, size);
|
| - }
|
| -
|
| - return status;
|
| + var rect = new goog.math.Rect(0, 0, 0, 0);
|
| + rect.left = absolutePos.x;
|
| + rect.top = absolutePos.y;
|
| + rect.width = elementSize.width;
|
| + rect.height = elementSize.height;
|
| + return {rect: rect, status: status};
|
| };
|
|
|
|
|
| @@ -433,13 +482,24 @@ goog.positioning.adjustForViewport_ = function(pos, size, viewport, overflow) {
|
| status |= goog.positioning.OverflowStatus.ADJUSTED_X;
|
| }
|
|
|
| - // Left edge inside and right edge outside viewport, try to resize it.
|
| - if (pos.x < viewport.left &&
|
| - pos.x + size.width > viewport.right &&
|
| - overflow & goog.positioning.Overflow.RESIZE_WIDTH) {
|
| - size.width = Math.max(
|
| - size.width - ((pos.x + size.width) - viewport.right), 0);
|
| - status |= goog.positioning.OverflowStatus.WIDTH_ADJUSTED;
|
| + // Ensure object is inside the viewport width if required.
|
| + if (overflow & goog.positioning.Overflow.RESIZE_WIDTH) {
|
| + // Move left edge inside viewport.
|
| + var originalX = pos.x;
|
| + if (pos.x < viewport.left) {
|
| + pos.x = viewport.left;
|
| + status |= goog.positioning.OverflowStatus.WIDTH_ADJUSTED;
|
| + }
|
| +
|
| + // Shrink width to inside right of viewport.
|
| + if (pos.x + size.width > viewport.right) {
|
| + // Set the width to be either the new maximum width within the viewport
|
| + // or the width originally within the viewport, whichever is less.
|
| + size.width = Math.min(
|
| + viewport.right - pos.x, originalX + size.width - viewport.left);
|
| + size.width = Math.max(size.width, 0);
|
| + status |= goog.positioning.OverflowStatus.WIDTH_ADJUSTED;
|
| + }
|
| }
|
|
|
| // Right edge outside viewport, try to move it.
|
| @@ -464,22 +524,24 @@ goog.positioning.adjustForViewport_ = function(pos, size, viewport, overflow) {
|
| status |= goog.positioning.OverflowStatus.ADJUSTED_Y;
|
| }
|
|
|
| - // Bottom edge inside and top edge outside viewport, try to resize it.
|
| - if (pos.y <= viewport.top &&
|
| - pos.y + size.height < viewport.bottom &&
|
| - overflow & goog.positioning.Overflow.RESIZE_HEIGHT) {
|
| - size.height = Math.max(size.height - (viewport.top - pos.y), 0);
|
| - pos.y = viewport.top;
|
| - status |= goog.positioning.OverflowStatus.HEIGHT_ADJUSTED;
|
| - }
|
| + // Ensure object is inside the viewport height if required.
|
| + if (overflow & goog.positioning.Overflow.RESIZE_HEIGHT) {
|
| + // Move top edge inside viewport.
|
| + var originalY = pos.y;
|
| + if (pos.y < viewport.top) {
|
| + pos.y = viewport.top;
|
| + status |= goog.positioning.OverflowStatus.HEIGHT_ADJUSTED;
|
| + }
|
|
|
| - // Top edge inside and bottom edge outside viewport, try to resize it.
|
| - if (pos.y >= viewport.top &&
|
| - pos.y + size.height > viewport.bottom &&
|
| - overflow & goog.positioning.Overflow.RESIZE_HEIGHT) {
|
| - size.height = Math.max(
|
| - size.height - ((pos.y + size.height) - viewport.bottom), 0);
|
| - status |= goog.positioning.OverflowStatus.HEIGHT_ADJUSTED;
|
| + // Shrink height to inside bottom of viewport.
|
| + if (pos.y + size.height > viewport.bottom) {
|
| + // Set the height to be either the new maximum height within the viewport
|
| + // or the height originally within the viewport, whichever is less.
|
| + size.height = Math.min(
|
| + viewport.bottom - pos.y, originalY + size.height - viewport.top);
|
| + size.height = Math.max(size.height, 0);
|
| + status |= goog.positioning.OverflowStatus.HEIGHT_ADJUSTED;
|
| + }
|
| }
|
|
|
| // Bottom edge outside viewport, try to move it.
|
|
|