Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / page / actions / gesture_common.js
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // This file provides common functionality for synthetic gesture actions.
6 'use strict';
7
8 (function() {
9
10   function getBoundingVisibleRect(el) {
11     var bound = el.getBoundingClientRect();
12     var rect = { top: bound.top,
13                  left: bound.left,
14                  width: bound.width,
15                  height: bound.height };
16     if (rect.top < 0) {
17       rect.height += rect.top;
18       rect.top = 0;
19     }
20     if (rect.left < 0) {
21       rect.width += rect.left;
22       rect.left = 0;
23     }
24
25     var outsideHeight = (rect.top + rect.height) - window.innerHeight;
26     var outsideWidth = (rect.left + rect.width) - window.innerWidth;
27
28     if (outsideHeight > 0) {
29       rect.height -= outsideHeight;
30     }
31     if (outsideWidth > 0) {
32       rect.width -= outsideWidth;
33     }
34     return rect;
35   };
36
37   window.__GestureCommon_GetBoundingVisibleRect = getBoundingVisibleRect;
38 })();