1// Copyright (c) 2011 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#ifndef CHROME_BROWSER_UI_VIEWS_GENERIC_INFO_VIEW_H_
6#define CHROME_BROWSER_UI_VIEWS_GENERIC_INFO_VIEW_H_
7#pragma once
8
9#include "base/gtest_prod_util.h"
10#include "base/memory/scoped_ptr.h"
11#include "base/string16.h"
12#include "views/view.h"
13
14namespace views {
15class GridLayout;
16class Label;
17class Textfield;
18}
19
20// GenericInfoView, displays a tabular grid of read-only textual information,
21// <name, value> pairs. The fixed number of rows must be known at the time of
22// construction.
23class GenericInfoView : public views::View {
24 public:
25  // Constructs a info view with |number_of_rows| and populated with
26  // empty strings.
27  explicit GenericInfoView(int number_of_rows);
28
29  // Constructs a info view with |number_of_rows|, and populates
30  // the name column with localized strings having the given
31  // |name_string_ids|. The array of ids should contain |number_of_rows|
32  // values and should remain valid for the life of the view.
33  GenericInfoView(int number_of_rows, const int name_string_ids[]);
34
35  // The following methods should only be called after
36  // the view has been added to a view hierarchy.
37  void SetNameByStringId(int row, int id);
38  void SetName(int row, const string16& name);
39  void SetValue(int row, const string16& value);
40  void ClearValues() {
41    const string16 kEmptyString;
42    for (int i = 0; i < number_of_rows_; ++i)
43      SetValue(i, kEmptyString);
44  }
45
46 protected:
47  // views::View override
48  virtual void ViewHierarchyChanged(
49      bool is_add, views::View* parent, views::View* child);
50
51 private:
52  FRIEND_TEST_ALL_PREFIXES(GenericInfoViewTest, GenericInfoView);
53
54  void InitGenericInfoView();
55  void AddRow(int layout_id, views::GridLayout* layout,
56              views::Label* name, views::Textfield* value);
57
58  const int number_of_rows_;
59  const int* name_string_ids_;
60  scoped_array<views::Label*> name_views_;
61  scoped_array<views::Textfield*> value_views_;
62
63  DISALLOW_COPY_AND_ASSIGN(GenericInfoView);
64};
65
66#endif  // CHROME_BROWSER_UI_VIEWS_GENERIC_INFO_VIEW_H_
67
68