summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-16 19:57:31 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-16 19:57:31 +0000
commit67c565eee0066426a716b2c5085a7af04f52e73a (patch)
tree9919e990c47bed244400e4d7c651d9f099726d83 /app
parent09c6dec4e18784861660f716d038035be9540601 (diff)
downloadchromium_src-67c565eee0066426a716b2c5085a7af04f52e73a.zip
chromium_src-67c565eee0066426a716b2c5085a7af04f52e73a.tar.gz
chromium_src-67c565eee0066426a716b2c5085a7af04f52e73a.tar.bz2
Move TableModel out of views/ and into app/.
Remove stub implementation in temp_scaffolding_stubs.h Use l10n_util collator helper function in TableModel::Compare Review URL: http://codereview.chromium.org/126184 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18518 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r--app/app.gyp3
-rw-r--r--app/table_model.cc106
-rw-r--r--app/table_model.h153
-rw-r--r--app/table_model_observer.h25
4 files changed, 287 insertions, 0 deletions
diff --git a/app/app.gyp b/app/app.gyp
index 3d1d0a5..e316d41d 100644
--- a/app/app.gyp
+++ b/app/app.gyp
@@ -104,6 +104,9 @@
'theme_provider.h',
'throb_animation.cc',
'throb_animation.h',
+ 'table_model.cc',
+ 'table_model.h',
+ 'table_model_observer.h',
],
'direct_dependent_settings': {
'include_dirs': [
diff --git a/app/table_model.cc b/app/table_model.cc
new file mode 100644
index 0000000..0f35905
--- /dev/null
+++ b/app/table_model.cc
@@ -0,0 +1,106 @@
+// Copyright (c) 2009 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.
+
+#include "app/table_model.h"
+
+#include "app/l10n_util.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+
+// TableColumn -----------------------------------------------------------------
+
+TableColumn::TableColumn()
+ : id(0),
+ title(),
+ alignment(LEFT),
+ width(-1),
+ percent(),
+ min_visible_width(0),
+ sortable(false) {
+}
+
+TableColumn::TableColumn(int id, const std::wstring& title,
+ Alignment alignment,
+ int width)
+ : id(id),
+ title(title),
+ alignment(alignment),
+ width(width),
+ percent(0),
+ min_visible_width(0),
+ sortable(false) {
+}
+
+TableColumn::TableColumn(int id, const std::wstring& title,
+ Alignment alignment, int width, float percent)
+ : id(id),
+ title(title),
+ alignment(alignment),
+ width(width),
+ percent(percent),
+ min_visible_width(0),
+ sortable(false) {
+}
+
+// It's common (but not required) to use the title's IDS_* tag as the column
+// id. In this case, the provided conveniences look up the title string on
+// bahalf of the caller.
+TableColumn::TableColumn(int id, Alignment alignment, int width)
+ : id(id),
+ alignment(alignment),
+ width(width),
+ percent(0),
+ min_visible_width(0),
+ sortable(false) {
+ title = l10n_util::GetString(id);
+}
+
+TableColumn::TableColumn(int id, Alignment alignment, int width, float percent)
+ : id(id),
+ alignment(alignment),
+ width(width),
+ percent(percent),
+ min_visible_width(0),
+ sortable(false) {
+ title = l10n_util::GetString(id);
+}
+
+// TableModel -----------------------------------------------------------------
+
+// Used for sorting.
+static Collator* collator = NULL;
+
+SkBitmap TableModel::GetIcon(int row) {
+ return SkBitmap();
+}
+
+int TableModel::CompareValues(int row1, int row2, int column_id) {
+ DCHECK(row1 >= 0 && row1 < RowCount() &&
+ row2 >= 0 && row2 < RowCount());
+ std::wstring value1 = GetText(row1, column_id);
+ std::wstring value2 = GetText(row2, column_id);
+ Collator* collator = GetCollator();
+
+ if (collator)
+ return l10n_util::CompareStringWithCollator(collator, value1, value2);
+
+ NOTREACHED();
+ return 0;
+}
+
+Collator* TableModel::GetCollator() {
+ if (!collator) {
+ UErrorCode create_status = U_ZERO_ERROR;
+ collator = Collator::createInstance(create_status);
+ if (!U_SUCCESS(create_status)) {
+ collator = NULL;
+ NOTREACHED();
+ }
+ }
+ return collator;
+}
+
+void TableModel::ClearCollator() {
+ delete collator;
+ collator = NULL;
+}
diff --git a/app/table_model.h b/app/table_model.h
new file mode 100644
index 0000000..ba7043e
--- /dev/null
+++ b/app/table_model.h
@@ -0,0 +1,153 @@
+// Copyright (c) 2009 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.
+
+#ifndef APP_TABLE_MODEL_H_
+#define APP_TABLE_MODEL_H_
+
+#include <string>
+#include <vector>
+
+#include "base/logging.h"
+#include "unicode/coll.h"
+
+class SkBitmap;
+
+class TableModelObserver;
+
+// The model driving the TableView.
+class TableModel {
+ public:
+ // See HasGroups, get GetGroupID for details as to how this is used.
+ struct Group {
+ // The title text for the group.
+ std::wstring title;
+
+ // Unique id for the group.
+ int id;
+ };
+ typedef std::vector<Group> Groups;
+
+ // Number of rows in the model.
+ virtual int RowCount() = 0;
+
+ // Returns the value at a particular location in text.
+ virtual std::wstring GetText(int row, int column_id) = 0;
+
+ // Returns the small icon (16x16) that should be displayed in the first
+ // column before the text. This is only used when the TableView was created
+ // with the ICON_AND_TEXT table type. Returns an isNull() bitmap if there is
+ // no bitmap.
+ virtual SkBitmap GetIcon(int row);
+
+ // Sets whether a particular row is checked. This is only invoked
+ // if the TableView was created with show_check_in_first_column true.
+ virtual void SetChecked(int row, bool is_checked) {
+ NOTREACHED();
+ }
+
+ // Returns whether a particular row is checked. This is only invoked
+ // if the TableView was created with show_check_in_first_column true.
+ virtual bool IsChecked(int row) {
+ return false;
+ }
+
+ // Returns true if the TableView has groups. Groups provide a way to visually
+ // delineate the rows in a table view. When groups are enabled table view
+ // shows a visual separator for each group, followed by all the rows in
+ // the group.
+ //
+ // On win2k a visual separator is not rendered for the group headers.
+ virtual bool HasGroups() { return false; }
+
+ // Returns the groups.
+ // This is only used if HasGroups returns true.
+ virtual Groups GetGroups() {
+ // If you override HasGroups to return true, you must override this as
+ // well.
+ NOTREACHED();
+ return std::vector<Group>();
+ }
+
+ // Returns the group id of the specified row.
+ // This is only used if HasGroups returns true.
+ virtual int GetGroupID(int row) {
+ // If you override HasGroups to return true, you must override this as
+ // well.
+ NOTREACHED();
+ return 0;
+ }
+
+ // Sets the observer for the model. The TableView should NOT take ownership
+ // of the observer.
+ virtual void SetObserver(TableModelObserver* observer) = 0;
+
+ // Compares the values in the column with id |column_id| for the two rows.
+ // Returns a value < 0, == 0 or > 0 as to whether the first value is
+ // <, == or > the second value.
+ //
+ // This implementation does a case insensitive locale specific string
+ // comparison.
+ virtual int CompareValues(int row1, int row2, int column_id);
+
+ // Reset the collator.
+ void ClearCollator();
+
+ protected:
+ // Returns the collator used by CompareValues.
+ Collator* GetCollator();
+};
+
+// TableColumn specifies the title, alignment and size of a particular column.
+struct TableColumn {
+ enum Alignment {
+ LEFT, RIGHT, CENTER
+ };
+
+ TableColumn();
+ TableColumn(int id, const std::wstring& title,
+ Alignment alignment, int width);
+ TableColumn(int id, const std::wstring& title,
+ Alignment alignment, int width, float percent);
+
+ // It's common (but not required) to use the title's IDS_* tag as the column
+ // id. In this case, the provided conveniences look up the title string on
+ // bahalf of the caller.
+ TableColumn(int id, Alignment alignment, int width);
+ TableColumn(int id, Alignment alignment, int width, float percent);
+
+ // A unique identifier for the column.
+ int id;
+
+ // The title for the column.
+ std::wstring title;
+
+ // Alignment for the content.
+ Alignment alignment;
+
+ // The size of a column may be specified in two ways:
+ // 1. A fixed width. Set the width field to a positive number and the
+ // column will be given that width, in pixels.
+ // 2. As a percentage of the available width. If width is -1, and percent is
+ // > 0, the column is given a width of
+ // available_width * percent / total_percent.
+ // 3. If the width == -1 and percent == 0, the column is autosized based on
+ // the width of the column header text.
+ //
+ // Sizing is done in four passes. Fixed width columns are given
+ // their width, percentages are applied, autosized columns are autosized,
+ // and finally percentages are applied again taking into account the widths
+ // of autosized columns.
+ int width;
+ float percent;
+
+ // The minimum width required for all items in this column
+ // (including the header)
+ // to be visible.
+ int min_visible_width;
+
+ // Is this column sortable? Default is false
+ bool sortable;
+};
+
+#endif // APP_TABLE_MODEL_H_
diff --git a/app/table_model_observer.h b/app/table_model_observer.h
new file mode 100644
index 0000000..fcd50f4
--- /dev/null
+++ b/app/table_model_observer.h
@@ -0,0 +1,25 @@
+// Copyright (c) 2009 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.
+
+#ifndef APP_TABLE_MODEL_OBSERVER_H_
+#define APP_TABLE_MODEL_OBSERVER_H_
+
+// Observer for a TableModel. Anytime the model changes, it must notify its
+// observer.
+class TableModelObserver {
+ public:
+ // Invoked when the model has been completely changed.
+ virtual void OnModelChanged() = 0;
+
+ // Invoked when a range of items has changed.
+ virtual void OnItemsChanged(int start, int length) = 0;
+
+ // Invoked when new items are added.
+ virtual void OnItemsAdded(int start, int length) = 0;
+
+ // Invoked when a range of items has been removed.
+ virtual void OnItemsRemoved(int start, int length) = 0;
+};
+
+#endif // APP_TABLE_MODEL_OBSERVER_H_