Home | History | Annotate | Download | only in oak
      1 // Copyright (c) 2012 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 #include "ui/oak/oak_tree_model.h"
      6 
      7 #include "base/strings/utf_string_conversions.h"
      8 #include "ui/aura/root_window.h"
      9 #include "ui/aura/window.h"
     10 #include "ui/base/models/tree_node_model.h"
     11 
     12 namespace oak {
     13 namespace internal {
     14 
     15 base::string16 GetNodeTitleForWindow(aura::Window* window) {
     16   std::string window_name = window->name();
     17   if (window_name.empty())
     18     window_name.append("Unnamed window");
     19   return ASCIIToUTF16(window_name);
     20 }
     21 
     22 void AddChildWindows(aura::Window* parent_window, WindowNode* parent_node) {
     23   aura::Window::Windows::const_iterator it = parent_window->children().begin();
     24   for (; it != parent_window->children().end(); ++it) {
     25     WindowNode* child_node = new WindowNode(GetNodeTitleForWindow(*it), *it);
     26     parent_node->Add(child_node, parent_node->child_count());
     27     AddChildWindows(*it, child_node);
     28   }
     29 }
     30 
     31 TreeOfWindows* GenerateModel(aura::Window* root) {
     32   WindowNode* root_node = new WindowNode(GetNodeTitleForWindow(root), root);
     33   TreeOfWindows* tree = new TreeOfWindows(root_node);
     34   AddChildWindows(root, root_node);
     35   return tree;
     36 }
     37 
     38 }  // namespace internal
     39 }  // namespace oak
     40