roundedpanel.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. // Copyright 2008 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview Class definition for a rounded corner panel.
  16. * @supported IE 6.0+, Safari 2.0+, Firefox 1.5+, Opera 9.2+.
  17. * @see ../demos/roundedpanel.html
  18. */
  19. goog.provide('goog.ui.BaseRoundedPanel');
  20. goog.provide('goog.ui.CssRoundedPanel');
  21. goog.provide('goog.ui.GraphicsRoundedPanel');
  22. goog.provide('goog.ui.RoundedPanel');
  23. goog.provide('goog.ui.RoundedPanel.Corner');
  24. goog.require('goog.asserts');
  25. goog.require('goog.dom');
  26. goog.require('goog.dom.TagName');
  27. goog.require('goog.dom.classlist');
  28. goog.require('goog.graphics');
  29. goog.require('goog.graphics.Path');
  30. goog.require('goog.graphics.SolidFill');
  31. goog.require('goog.graphics.Stroke');
  32. goog.require('goog.math');
  33. goog.require('goog.math.Coordinate');
  34. goog.require('goog.style');
  35. goog.require('goog.ui.Component');
  36. goog.require('goog.userAgent');
  37. /**
  38. * Factory method that returns an instance of a BaseRoundedPanel.
  39. * @param {number} radius The radius of the rounded corner(s), in pixels.
  40. * @param {number} borderWidth The thickness of the border, in pixels.
  41. * @param {string} borderColor The border color of the panel.
  42. * @param {string=} opt_backgroundColor The background color of the panel.
  43. * @param {number=} opt_corners The corners of the panel to be rounded. Any
  44. * corners not specified will be rendered as square corners. Will default
  45. * to all square corners if not specified.
  46. * @param {goog.dom.DomHelper=} opt_domHelper The DOM helper object for the
  47. * document we want to render in.
  48. * @return {!goog.ui.BaseRoundedPanel} An instance of a
  49. * goog.ui.BaseRoundedPanel subclass.
  50. * TODO(user): deprecate this class, which has <5 usages and only really
  51. * matters for IE8, and then only stylistically.
  52. */
  53. goog.ui.RoundedPanel.create = function(
  54. radius, borderWidth, borderColor, opt_backgroundColor, opt_corners,
  55. opt_domHelper) {
  56. // This variable checks for the presence of Safari 3.0+ or Gecko 1.9+,
  57. // which can leverage special CSS styles to create rounded corners.
  58. var isCssReady =
  59. (goog.userAgent.WEBKIT && goog.userAgent.isVersionOrHigher('500')) ||
  60. (goog.userAgent.GECKO && goog.userAgent.isVersionOrHigher('1.9a')) ||
  61. goog.userAgent.EDGE;
  62. if (isCssReady) {
  63. // Safari 3.0+ and Firefox 3.0+ support this instance.
  64. return new goog.ui.CssRoundedPanel(
  65. radius, borderWidth, borderColor, opt_backgroundColor, opt_corners,
  66. opt_domHelper);
  67. } else {
  68. return new goog.ui.GraphicsRoundedPanel(
  69. radius, borderWidth, borderColor, opt_backgroundColor, opt_corners,
  70. opt_domHelper);
  71. }
  72. };
  73. /**
  74. * Enum for specifying which corners to render.
  75. * @enum {number}
  76. */
  77. goog.ui.RoundedPanel.Corner = {
  78. NONE: 0,
  79. BOTTOM_LEFT: 2,
  80. TOP_LEFT: 4,
  81. LEFT: 6, // BOTTOM_LEFT | TOP_LEFT
  82. TOP_RIGHT: 8,
  83. TOP: 12, // TOP_LEFT | TOP_RIGHT
  84. BOTTOM_RIGHT: 1,
  85. BOTTOM: 3, // BOTTOM_LEFT | BOTTOM_RIGHT
  86. RIGHT: 9, // TOP_RIGHT | BOTTOM_RIGHT
  87. ALL: 15 // TOP | BOTTOM
  88. };
  89. /**
  90. * CSS class name suffixes for the elements comprising the RoundedPanel.
  91. * @enum {string}
  92. * @private
  93. */
  94. goog.ui.RoundedPanel.Classes_ = {
  95. BACKGROUND: goog.getCssName('goog-roundedpanel-background'),
  96. PANEL: goog.getCssName('goog-roundedpanel'),
  97. CONTENT: goog.getCssName('goog-roundedpanel-content')
  98. };
  99. /**
  100. * Base class for the hierarchy of RoundedPanel classes. Do not
  101. * instantiate directly. Instead, call goog.ui.RoundedPanel.create().
  102. * The HTML structure for the RoundedPanel is:
  103. * <pre>
  104. * - div (Contains the background and content. Class name: goog-roundedpanel)
  105. * - div (Contains the background/rounded corners. Class name:
  106. * goog-roundedpanel-bg)
  107. * - div (Contains the content. Class name: goog-roundedpanel-content)
  108. * </pre>
  109. * @param {number} radius The radius of the rounded corner(s), in pixels.
  110. * @param {number} borderWidth The thickness of the border, in pixels.
  111. * @param {string} borderColor The border color of the panel.
  112. * @param {string=} opt_backgroundColor The background color of the panel.
  113. * @param {number=} opt_corners The corners of the panel to be rounded. Any
  114. * corners not specified will be rendered as square corners. Will default
  115. * to all square corners if not specified.
  116. * @param {goog.dom.DomHelper=} opt_domHelper The DOM helper object for the
  117. * document we want to render in.
  118. * @extends {goog.ui.Component}
  119. * @constructor
  120. */
  121. goog.ui.BaseRoundedPanel = function(
  122. radius, borderWidth, borderColor, opt_backgroundColor, opt_corners,
  123. opt_domHelper) {
  124. goog.ui.Component.call(this, opt_domHelper);
  125. /**
  126. * The radius of the rounded corner(s), in pixels.
  127. * @type {number}
  128. * @private
  129. */
  130. this.radius_ = radius;
  131. /**
  132. * The thickness of the border, in pixels.
  133. * @type {number}
  134. * @private
  135. */
  136. this.borderWidth_ = borderWidth;
  137. /**
  138. * The border color of the panel.
  139. * @type {string}
  140. * @private
  141. */
  142. this.borderColor_ = borderColor;
  143. /**
  144. * The background color of the panel.
  145. * @type {?string}
  146. * @private
  147. */
  148. this.backgroundColor_ = opt_backgroundColor || null;
  149. /**
  150. * The corners of the panel to be rounded; defaults to
  151. * goog.ui.RoundedPanel.Corner.NONE
  152. * @type {number}
  153. * @private
  154. */
  155. this.corners_ = opt_corners || goog.ui.RoundedPanel.Corner.NONE;
  156. };
  157. goog.inherits(goog.ui.BaseRoundedPanel, goog.ui.Component);
  158. goog.tagUnsealableClass(goog.ui.BaseRoundedPanel);
  159. /**
  160. * The element containing the rounded corners and background.
  161. * @type {Element}
  162. * @private
  163. */
  164. goog.ui.BaseRoundedPanel.prototype.backgroundElement_;
  165. /**
  166. * The element containing the actual content.
  167. * @type {Element}
  168. * @private
  169. */
  170. goog.ui.BaseRoundedPanel.prototype.contentElement_;
  171. /**
  172. * This method performs all the necessary DOM manipulation to create the panel.
  173. * Overrides {@link goog.ui.Component#decorateInternal}.
  174. * @param {Element} element The element to decorate.
  175. * @protected
  176. * @override
  177. */
  178. goog.ui.BaseRoundedPanel.prototype.decorateInternal = function(element) {
  179. goog.ui.BaseRoundedPanel.superClass_.decorateInternal.call(this, element);
  180. goog.dom.classlist.add(
  181. goog.asserts.assert(this.getElement()),
  182. goog.ui.RoundedPanel.Classes_.PANEL);
  183. // Create backgroundElement_, and add it to the DOM.
  184. this.backgroundElement_ =
  185. this.getDomHelper().createElement(goog.dom.TagName.DIV);
  186. this.backgroundElement_.className = goog.ui.RoundedPanel.Classes_.BACKGROUND;
  187. this.getElement().appendChild(this.backgroundElement_);
  188. // Set contentElement_ by finding a child node within element_ with the
  189. // proper class name. If none exists, create it and add it to the DOM.
  190. this.contentElement_ = goog.dom.getElementsByTagNameAndClass(
  191. null, goog.ui.RoundedPanel.Classes_.CONTENT, this.getElement())[0];
  192. if (!this.contentElement_) {
  193. this.contentElement_ = this.getDomHelper().createDom(goog.dom.TagName.DIV);
  194. this.contentElement_.className = goog.ui.RoundedPanel.Classes_.CONTENT;
  195. this.getElement().appendChild(this.contentElement_);
  196. }
  197. };
  198. /** @override */
  199. goog.ui.BaseRoundedPanel.prototype.disposeInternal = function() {
  200. if (this.backgroundElement_) {
  201. this.getDomHelper().removeNode(this.backgroundElement_);
  202. this.backgroundElement_ = null;
  203. }
  204. this.contentElement_ = null;
  205. goog.ui.BaseRoundedPanel.superClass_.disposeInternal.call(this);
  206. };
  207. /**
  208. * Returns the DOM element containing the actual content.
  209. * @return {Element} The element containing the actual content (null if none).
  210. * @override
  211. */
  212. goog.ui.BaseRoundedPanel.prototype.getContentElement = function() {
  213. return this.contentElement_;
  214. };
  215. /**
  216. * RoundedPanel class specifically for browsers that support CSS attributes
  217. * for elements with rounded borders (ex. Safari 3.0+, Firefox 3.0+). Do not
  218. * instantiate directly. Instead, call goog.ui.RoundedPanel.create().
  219. * @param {number} radius The radius of the rounded corner(s), in pixels.
  220. * @param {number} borderWidth The thickness of the border, in pixels.
  221. * @param {string} borderColor The border color of the panel.
  222. * @param {string=} opt_backgroundColor The background color of the panel.
  223. * @param {number=} opt_corners The corners of the panel to be rounded. Any
  224. * corners not specified will be rendered as square corners. Will
  225. * default to all square corners if not specified.
  226. * @param {goog.dom.DomHelper=} opt_domHelper The DOM helper object for the
  227. * document we want to render in.
  228. * @extends {goog.ui.BaseRoundedPanel}
  229. * @constructor
  230. * @final
  231. */
  232. goog.ui.CssRoundedPanel = function(
  233. radius, borderWidth, borderColor, opt_backgroundColor, opt_corners,
  234. opt_domHelper) {
  235. goog.ui.BaseRoundedPanel.call(
  236. this, radius, borderWidth, borderColor, opt_backgroundColor, opt_corners,
  237. opt_domHelper);
  238. };
  239. goog.inherits(goog.ui.CssRoundedPanel, goog.ui.BaseRoundedPanel);
  240. /**
  241. * This method performs all the necessary DOM manipulation to create the panel.
  242. * Overrides {@link goog.ui.Component#decorateInternal}.
  243. * @param {Element} element The element to decorate.
  244. * @protected
  245. * @override
  246. */
  247. goog.ui.CssRoundedPanel.prototype.decorateInternal = function(element) {
  248. goog.ui.CssRoundedPanel.superClass_.decorateInternal.call(this, element);
  249. // Set the border width and background color, if needed.
  250. this.backgroundElement_.style.border =
  251. this.borderWidth_ + 'px solid ' + this.borderColor_;
  252. if (this.backgroundColor_) {
  253. this.backgroundElement_.style.backgroundColor = this.backgroundColor_;
  254. }
  255. // Set radii of the appropriate rounded corners.
  256. if (this.corners_ == goog.ui.RoundedPanel.Corner.ALL) {
  257. var styleName = this.getStyle_(goog.ui.RoundedPanel.Corner.ALL);
  258. this.backgroundElement_.style[styleName] = this.radius_ + 'px';
  259. } else {
  260. var topLeftRadius =
  261. this.corners_ & goog.ui.RoundedPanel.Corner.TOP_LEFT ? this.radius_ : 0;
  262. var cornerStyle = this.getStyle_(goog.ui.RoundedPanel.Corner.TOP_LEFT);
  263. this.backgroundElement_.style[cornerStyle] = topLeftRadius + 'px';
  264. var topRightRadius = this.corners_ & goog.ui.RoundedPanel.Corner.TOP_RIGHT ?
  265. this.radius_ :
  266. 0;
  267. cornerStyle = this.getStyle_(goog.ui.RoundedPanel.Corner.TOP_RIGHT);
  268. this.backgroundElement_.style[cornerStyle] = topRightRadius + 'px';
  269. var bottomRightRadius =
  270. this.corners_ & goog.ui.RoundedPanel.Corner.BOTTOM_RIGHT ?
  271. this.radius_ :
  272. 0;
  273. cornerStyle = this.getStyle_(goog.ui.RoundedPanel.Corner.BOTTOM_RIGHT);
  274. this.backgroundElement_.style[cornerStyle] = bottomRightRadius + 'px';
  275. var bottomLeftRadius =
  276. this.corners_ & goog.ui.RoundedPanel.Corner.BOTTOM_LEFT ? this.radius_ :
  277. 0;
  278. cornerStyle = this.getStyle_(goog.ui.RoundedPanel.Corner.BOTTOM_LEFT);
  279. this.backgroundElement_.style[cornerStyle] = bottomLeftRadius + 'px';
  280. }
  281. };
  282. /**
  283. * This method returns the CSS style based on the corner of the panel, and the
  284. * user-agent.
  285. * @param {number} corner The corner whose style name to retrieve.
  286. * @private
  287. * @return {string} The CSS style based on the specified corner.
  288. */
  289. goog.ui.CssRoundedPanel.prototype.getStyle_ = function(corner) {
  290. // Determine the proper corner to work with.
  291. var cssCorner, suffixLeft, suffixRight;
  292. if (goog.userAgent.WEBKIT) {
  293. suffixLeft = 'Left';
  294. suffixRight = 'Right';
  295. } else {
  296. suffixLeft = 'left';
  297. suffixRight = 'right';
  298. }
  299. switch (corner) {
  300. case goog.ui.RoundedPanel.Corner.ALL:
  301. cssCorner = '';
  302. break;
  303. case goog.ui.RoundedPanel.Corner.TOP_LEFT:
  304. cssCorner = 'Top' + suffixLeft;
  305. break;
  306. case goog.ui.RoundedPanel.Corner.TOP_RIGHT:
  307. cssCorner = 'Top' + suffixRight;
  308. break;
  309. case goog.ui.RoundedPanel.Corner.BOTTOM_LEFT:
  310. cssCorner = 'Bottom' + suffixLeft;
  311. break;
  312. case goog.ui.RoundedPanel.Corner.BOTTOM_RIGHT:
  313. cssCorner = 'Bottom' + suffixRight;
  314. break;
  315. }
  316. return goog.userAgent.WEBKIT ? 'WebkitBorder' + cssCorner + 'Radius' :
  317. 'MozBorderRadius' + cssCorner;
  318. };
  319. /**
  320. * RoundedPanel class that uses goog.graphics to create the rounded corners.
  321. * Do not instantiate directly. Instead, call goog.ui.RoundedPanel.create().
  322. * @param {number} radius The radius of the rounded corner(s), in pixels.
  323. * @param {number} borderWidth The thickness of the border, in pixels.
  324. * @param {string} borderColor The border color of the panel.
  325. * @param {string=} opt_backgroundColor The background color of the panel.
  326. * @param {number=} opt_corners The corners of the panel to be rounded. Any
  327. * corners not specified will be rendered as square corners. Will
  328. * default to all square corners if not specified.
  329. * @param {goog.dom.DomHelper=} opt_domHelper The DOM helper object for the
  330. * document we want to render in.
  331. * @extends {goog.ui.BaseRoundedPanel}
  332. * @constructor
  333. * @final
  334. */
  335. goog.ui.GraphicsRoundedPanel = function(
  336. radius, borderWidth, borderColor, opt_backgroundColor, opt_corners,
  337. opt_domHelper) {
  338. goog.ui.BaseRoundedPanel.call(
  339. this, radius, borderWidth, borderColor, opt_backgroundColor, opt_corners,
  340. opt_domHelper);
  341. };
  342. goog.inherits(goog.ui.GraphicsRoundedPanel, goog.ui.BaseRoundedPanel);
  343. /**
  344. * A 4-element array containing the circle centers for the arcs in the
  345. * bottom-left, top-left, top-right, and bottom-right corners, respectively.
  346. * @type {Array<goog.math.Coordinate>}
  347. * @private
  348. */
  349. goog.ui.GraphicsRoundedPanel.prototype.arcCenters_;
  350. /**
  351. * A 4-element array containing the start coordinates for rendering the arcs
  352. * in the bottom-left, top-left, top-right, and bottom-right corners,
  353. * respectively.
  354. * @type {Array<goog.math.Coordinate>}
  355. * @private
  356. */
  357. goog.ui.GraphicsRoundedPanel.prototype.cornerStarts_;
  358. /**
  359. * A 4-element array containing the arc end angles for the bottom-left,
  360. * top-left, top-right, and bottom-right corners, respectively.
  361. * @type {Array<number>}
  362. * @private
  363. */
  364. goog.ui.GraphicsRoundedPanel.prototype.endAngles_;
  365. /**
  366. * Graphics object for rendering the background.
  367. * @type {goog.graphics.AbstractGraphics}
  368. * @private
  369. */
  370. goog.ui.GraphicsRoundedPanel.prototype.graphics_;
  371. /**
  372. * A 4-element array containing the rounded corner radii for the bottom-left,
  373. * top-left, top-right, and bottom-right corners, respectively.
  374. * @type {Array<number>}
  375. * @private
  376. */
  377. goog.ui.GraphicsRoundedPanel.prototype.radii_;
  378. /**
  379. * A 4-element array containing the arc start angles for the bottom-left,
  380. * top-left, top-right, and bottom-right corners, respectively.
  381. * @type {Array<number>}
  382. * @private
  383. */
  384. goog.ui.GraphicsRoundedPanel.prototype.startAngles_;
  385. /**
  386. * Thickness constant used as an offset to help determine where to start
  387. * rendering.
  388. * @type {number}
  389. * @private
  390. */
  391. goog.ui.GraphicsRoundedPanel.BORDER_WIDTH_FACTOR_ = 1 / 2;
  392. /**
  393. * This method performs all the necessary DOM manipulation to create the panel.
  394. * Overrides {@link goog.ui.Component#decorateInternal}.
  395. * @param {Element} element The element to decorate.
  396. * @protected
  397. * @override
  398. */
  399. goog.ui.GraphicsRoundedPanel.prototype.decorateInternal = function(element) {
  400. goog.ui.GraphicsRoundedPanel.superClass_.decorateInternal.call(this, element);
  401. // Calculate the points and angles for creating the rounded corners. Then
  402. // instantiate a Graphics object for drawing purposes.
  403. var elementSize = goog.style.getSize(this.getElement());
  404. this.calculateArcParameters_(elementSize);
  405. this.graphics_ = goog.graphics.createGraphics(
  406. /** @type {number} */ (elementSize.width),
  407. /** @type {number} */ (elementSize.height),
  408. /** @type {number} */ (elementSize.width),
  409. /** @type {number} */ (elementSize.height), this.getDomHelper());
  410. this.graphics_.createDom();
  411. // Create the path, starting from the bottom-right corner, moving clockwise.
  412. // End with the top-right corner.
  413. var path = new goog.graphics.Path();
  414. for (var i = 0; i < 4; i++) {
  415. if (this.radii_[i]) {
  416. // If radius > 0, draw an arc, moving to the first point and drawing
  417. // a line to the others.
  418. var cx = this.arcCenters_[i].x;
  419. var cy = this.arcCenters_[i].y;
  420. var rx = this.radii_[i];
  421. var ry = rx;
  422. var fromAngle = this.startAngles_[i];
  423. var extent = this.endAngles_[i] - fromAngle;
  424. var startX = cx + goog.math.angleDx(fromAngle, rx);
  425. var startY = cy + goog.math.angleDy(fromAngle, ry);
  426. if (i > 0) {
  427. var currentPoint = path.getCurrentPoint();
  428. if (!currentPoint || startX != currentPoint[0] ||
  429. startY != currentPoint[1]) {
  430. path.lineTo(startX, startY);
  431. }
  432. } else {
  433. path.moveTo(startX, startY);
  434. }
  435. path.arcTo(rx, ry, fromAngle, extent);
  436. } else if (i == 0) {
  437. // If we're just starting out (ie. i == 0), move to the starting point.
  438. path.moveTo(this.cornerStarts_[i].x, this.cornerStarts_[i].y);
  439. } else {
  440. // Otherwise, draw a line to the starting point.
  441. path.lineTo(this.cornerStarts_[i].x, this.cornerStarts_[i].y);
  442. }
  443. }
  444. // Close the path, create a stroke object, and fill the enclosed area, if
  445. // needed. Then render the path.
  446. path.close();
  447. var stroke = this.borderWidth_ ?
  448. new goog.graphics.Stroke(this.borderWidth_, this.borderColor_) :
  449. null;
  450. var fill = this.backgroundColor_ ?
  451. new goog.graphics.SolidFill(this.backgroundColor_, 1) :
  452. null;
  453. this.graphics_.drawPath(path, stroke, fill);
  454. this.graphics_.render(this.backgroundElement_);
  455. };
  456. /** @override */
  457. goog.ui.GraphicsRoundedPanel.prototype.disposeInternal = function() {
  458. goog.ui.GraphicsRoundedPanel.superClass_.disposeInternal.call(this);
  459. this.graphics_.dispose();
  460. delete this.graphics_;
  461. delete this.radii_;
  462. delete this.cornerStarts_;
  463. delete this.arcCenters_;
  464. delete this.startAngles_;
  465. delete this.endAngles_;
  466. };
  467. /**
  468. * Calculates the start coordinates, circle centers, and angles, for the rounded
  469. * corners at each corner of the panel.
  470. * @param {goog.math.Size} elementSize The size of element_.
  471. * @private
  472. */
  473. goog.ui.GraphicsRoundedPanel.prototype.calculateArcParameters_ = function(
  474. elementSize) {
  475. // Initialize the arrays containing the key points and angles.
  476. this.radii_ = [];
  477. this.cornerStarts_ = [];
  478. this.arcCenters_ = [];
  479. this.startAngles_ = [];
  480. this.endAngles_ = [];
  481. // Set the start points, circle centers, and angles for the bottom-right,
  482. // bottom-left, top-left and top-right corners, in that order.
  483. var angleInterval = 90;
  484. var borderWidthOffset =
  485. this.borderWidth_ * goog.ui.GraphicsRoundedPanel.BORDER_WIDTH_FACTOR_;
  486. var radius, xStart, yStart, xCenter, yCenter, startAngle, endAngle;
  487. for (var i = 0; i < 4; i++) {
  488. var corner = Math.pow(2, i); // Determines which corner we're dealing with.
  489. var isLeft = corner & goog.ui.RoundedPanel.Corner.LEFT;
  490. var isTop = corner & goog.ui.RoundedPanel.Corner.TOP;
  491. // Calculate the radius and the start coordinates.
  492. radius = corner & this.corners_ ? this.radius_ : 0;
  493. switch (corner) {
  494. case goog.ui.RoundedPanel.Corner.BOTTOM_LEFT:
  495. xStart = borderWidthOffset + radius;
  496. yStart = elementSize.height - borderWidthOffset;
  497. break;
  498. case goog.ui.RoundedPanel.Corner.TOP_LEFT:
  499. xStart = borderWidthOffset;
  500. yStart = radius + borderWidthOffset;
  501. break;
  502. case goog.ui.RoundedPanel.Corner.TOP_RIGHT:
  503. xStart = elementSize.width - radius - borderWidthOffset;
  504. yStart = borderWidthOffset;
  505. break;
  506. case goog.ui.RoundedPanel.Corner.BOTTOM_RIGHT:
  507. xStart = elementSize.width - borderWidthOffset;
  508. yStart = elementSize.height - radius - borderWidthOffset;
  509. break;
  510. }
  511. // Calculate the circle centers and start/end angles.
  512. xCenter = isLeft ? radius + borderWidthOffset :
  513. elementSize.width - radius - borderWidthOffset;
  514. yCenter = isTop ? radius + borderWidthOffset :
  515. elementSize.height - radius - borderWidthOffset;
  516. startAngle = angleInterval * i;
  517. endAngle = startAngle + angleInterval;
  518. // Append the radius, angles, and coordinates to their arrays.
  519. this.radii_[i] = radius;
  520. this.cornerStarts_[i] = new goog.math.Coordinate(xStart, yStart);
  521. this.arcCenters_[i] = new goog.math.Coordinate(xCenter, yCenter);
  522. this.startAngles_[i] = startAngle;
  523. this.endAngles_[i] = endAngle;
  524. }
  525. };