summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/options/options_focus_manager.js
blob: 972e1fea0db8764c2c07c3f7cc755d02ac0f7953 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

cr.define('options', function() {
  var FocusManager = cr.ui.FocusManager;
  var OptionsPage = options.OptionsPage;

  function OptionsFocusManager() {
  }

  cr.addSingletonGetter(OptionsFocusManager);

  OptionsFocusManager.prototype = {
    __proto__: FocusManager.prototype,

    /** @override */
    getFocusParent: function() {
      var topPage = OptionsPage.getTopmostVisiblePage().pageDiv;

      // The default page and search page include a search field that is a
      // sibling of the rest of the page instead of a child. Thus, use the
      // parent node to allow the search field to receive focus.
      if (topPage.parentNode.id == 'page-container')
        return topPage.parentNode;

      return topPage;
    },
  };

  return {
    OptionsFocusManager: OptionsFocusManager,
  };
});