1 // Copyright 2014 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.
6 * @fileoverview A widget hosting an HTML snippet.
9 goog.provide('cvox.OverlayWidget');
11 goog.require('cvox.DomUtil');
12 goog.require('cvox.SearchWidget');
16 * @param {string} snippet The HTML snippet to render.
18 * @extends {cvox.SearchWidget}
20 cvox.OverlayWidget = function(snippet) {
22 this.snippet_ = snippet;
24 goog.inherits(cvox.OverlayWidget, cvox.SearchWidget);
30 cvox.OverlayWidget.prototype.show = function() {
31 goog.base(this, 'show');
32 var host = document.createElement('DIV');
33 host.innerHTML = this.snippet_;
35 // Position the overlay over the current ChromeVox selection.
36 var hitPoint = cvox.DomUtil.elementToPoint(
37 cvox.ChromeVox.navigationManager.getCurrentNode());
38 host.style.position = 'absolute';
39 host.style.left = hitPoint.x;
40 host.style.top = hitPoint.y;
42 document.body.appendChild(host);
43 cvox.ChromeVox.navigationManager.updateSelToArbitraryNode(host);
51 cvox.OverlayWidget.prototype.hide = function(opt_noSync) {
53 goog.base(this, 'hide');
60 cvox.OverlayWidget.prototype.onKeyDown = function(evt) {
61 // Allow the base class to handle all keys first.
62 goog.base(this, 'onKeyDown', evt);
64 // Do not interfere with any key that exits the widget.
65 if (evt.keyCode == 13 || evt.keyCode == 27) { // Enter or escape.
69 // Bound navigation within the snippet for any other key.
70 var r = cvox.ChromeVox.navigationManager.isReversed();
71 if (!cvox.DomUtil.isDescendantOfNode(
72 cvox.ChromeVox.navigationManager.getCurrentNode(), this.host_)) {
74 cvox.ChromeVox.navigationManager.syncToBeginning();
76 cvox.ChromeVox.navigationManager.updateSelToArbitraryNode(this.host_);
79 cvox.ChromeVox.navigationManager.speakDescriptionArray(
80 cvox.ChromeVox.navigationManager.getDescription(),
81 cvox.QueueMode.FLUSH, null);