From e6771600ddcb67a80854ff8c268d599b267236f3 Mon Sep 17 00:00:00 2001
From: "pkasting@chromium.org"
 <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>
Date: Mon, 10 May 2010 18:07:51 +0000
Subject: Remove checkbox table support, as it is unused.

BUG=none
TEST=none
Review URL: http://codereview.chromium.org/2009007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46829 0039d316-1c4b-4281-b951-d872f2087c98
---
 views/controls/table/native_table_win.cc    | 31 ++-------
 views/controls/table/native_table_win.h     | 10 +--
 views/controls/table/table_view.cc          | 98 +++++++++--------------------
 views/controls/table/table_view.h           |  4 --
 views/controls/table/table_view_unittest.cc | 59 +----------------
 5 files changed, 39 insertions(+), 163 deletions(-)

(limited to 'views/controls/table')

diff --git a/views/controls/table/native_table_win.cc b/views/controls/table/native_table_win.cc
index 3422c3d..a30d1bf 100644
--- a/views/controls/table/native_table_win.cc
+++ b/views/controls/table/native_table_win.cc
@@ -266,7 +266,7 @@ bool NativeTableWin::ProcessMessage(UINT message, WPARAM w_param,
 
       case LVN_ITEMCHANGED: {
         // Notification that the state of an item has changed. The state
-        // includes such things as whether the item is selected or checked.
+        // includes such things as whether the item is selected.
         NMLISTVIEW* state_change = reinterpret_cast<NMLISTVIEW*>(hdr);
         if ((state_change->uChanged & LVIF_STATE) != 0) {
           if ((state_change->uOldState & LVIS_SELECTED) !=
@@ -274,14 +274,6 @@ bool NativeTableWin::ProcessMessage(UINT message, WPARAM w_param,
             // Selected state of the item changed.
             OnSelectedStateChanged();
           }
-          if ((state_change->uOldState & LVIS_STATEIMAGEMASK) !=
-              (state_change->uNewState & LVIS_STATEIMAGEMASK)) {
-            // Checked state of the item changed.
-            bool is_checked =
-                ((state_change->uNewState & LVIS_STATEIMAGEMASK) ==
-                INDEXTOSTATEIMAGEMASK(2));
-            OnCheckedStateChanged(state_change->iItem, is_checked);
-          }
         }
         break;
       }
@@ -335,12 +327,10 @@ void NativeTableWin::CreateNativeControl() {
                                table_->GetWidget()->GetNativeView(),
                                NULL, NULL, NULL);
 
-  // Make the selection extend across the row.
-  // Reduce overdraw/flicker artifacts by double buffering.
-  DWORD list_view_style = LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER;
-  if (table_->type() == CHECK_BOX_AND_TEXT)
-    list_view_style |= LVS_EX_CHECKBOXES;
-  ListView_SetExtendedListViewStyleEx(hwnd, 0, list_view_style);
+  // Reduce overdraw/flicker artifacts by double buffering.  Make the selection
+  // extend across the row.
+  ListView_SetExtendedListViewStyle(hwnd,
+                                    LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT);
   l10n_util::AdjustUIFontForWindow(hwnd);
 
   NativeControlCreated(hwnd);
@@ -439,11 +429,6 @@ bool NativeTableWin::OnKeyDown(base::KeyboardCode virtual_keycode) {
   return false;  // Let the key event be processed as ususal.
 }
 
-void NativeTableWin::OnCheckedStateChanged(int model_row, bool is_checked) {
-  if (!ignore_listview_change_)
-    table_->model()->SetChecked(model_row, is_checked);
-}
-
 LRESULT NativeTableWin::OnCustomDraw(NMLVCUSTOMDRAW* draw_info) {
   switch (draw_info->nmcd.dwDrawStage) {
     case CDDS_PREPAINT: {
@@ -545,15 +530,9 @@ void NativeTableWin::UpdateListViewCache(int start, int length, bool add) {
     for (int i = start; i < max_row; ++i) {
       item.iItem = i;
       item.lParam = i;
-      // We do not want to notify of the check state when we insert the items.
       ignore_listview_change_ = true;
       ListView_InsertItem(native_view(), &item);
       ignore_listview_change_ = false;
-      if (table_->type() == CHECK_BOX_AND_TEXT &&
-          table_->model()->IsChecked(i)) {
-        // Setting the state notifies of the check state change.
-        ListView_SetCheckState(native_view(), i, true);
-      }
     }
   }
 
diff --git a/views/controls/table/native_table_win.h b/views/controls/table/native_table_win.h
index 2725bb2..509febd 100644
--- a/views/controls/table/native_table_win.h
+++ b/views/controls/table/native_table_win.h
@@ -1,6 +1,6 @@
-// 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.
+// Copyright (c) 2010 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 VIEWS_CONTROLS_TABLE_NATIVE_TABLE_WIN_H_
 #define VIEWS_CONTROLS_TABLE_NATIVE_TABLE_WIN_H_
@@ -75,10 +75,6 @@ class NativeTableWin : public NativeControlWin, public NativeTableWrapper {
   // Overridden from NativeControl. Notifies the observer.
   virtual bool OnKeyDown(base::KeyboardCode virtual_keycode);
 
-  // Notification from the ListView that the checked state of the item has
-  // changed.
-  void OnCheckedStateChanged(int model_row, bool is_checked);
-
   // Custom drawing of our icons.
   LRESULT OnCustomDraw(NMLVCUSTOMDRAW* draw_info);
 
diff --git a/views/controls/table/table_view.cc b/views/controls/table/table_view.cc
index a39aff0..73ea02c 100644
--- a/views/controls/table/table_view.cc
+++ b/views/controls/table/table_view.cc
@@ -26,6 +26,17 @@
 #include "views/controls/native/native_view_host.h"
 #include "views/controls/table/table_view_observer.h"
 
+namespace {
+
+int GetViewIndexFromPoint(HWND window, const gfx::Point& p) {
+  LVHITTESTINFO hit_info = {0};
+  hit_info.pt.x = p.x();
+  hit_info.pt.y = p.y();
+  return ListView_HitTest(window, &hit_info);
+}
+
+}  // namespace
+
 namespace views {
 
 // Added to column width to prevent truncation.
@@ -500,15 +511,6 @@ bool TableView::GetCellColors(int model_row,
   return false;
 }
 
-static int GetViewIndexFromMouseEvent(HWND window, LPARAM l_param) {
-  int x = GET_X_LPARAM(l_param);
-  int y = GET_Y_LPARAM(l_param);
-  LVHITTESTINFO hit_info = {0};
-  hit_info.pt.x = x;
-  hit_info.pt.y = y;
-  return ListView_HitTest(window, &hit_info);
-}
-
 // static
 LRESULT CALLBACK TableView::TableWndProc(HWND window,
                                          UINT message,
@@ -547,10 +549,8 @@ LRESULT CALLBACK TableView::TableWndProc(HWND window,
             PtInRect(&client_rect, table_point)) {
           // The point is over the client area of the table, handle it ourself.
           // But first select the row if it isn't already selected.
-          LVHITTESTINFO hit_info = {0};
-          hit_info.pt.x = table_point.x;
-          hit_info.pt.y = table_point.y;
-          int view_index = ListView_HitTest(window, &hit_info);
+          int view_index =
+              GetViewIndexFromPoint(window, gfx::Point(table_point));
           if (view_index != -1) {
             int model_index = table_view->view_to_model(view_index);
             if (!table_view->IsItemSelected(model_index))
@@ -611,7 +611,7 @@ LRESULT CALLBACK TableView::TableWndProc(HWND window,
 
     case WM_MBUTTONDOWN: {
       if (w_param == MK_MBUTTON) {
-        int view_index = GetViewIndexFromMouseEvent(window, l_param);
+        int view_index = GetViewIndexFromPoint(window, gfx::Point(l_param));
         if (view_index != -1) {
           int model_index = table_view->view_to_model(view_index);
           // Clear all and select the row that was middle clicked.
@@ -628,7 +628,7 @@ LRESULT CALLBACK TableView::TableWndProc(HWND window,
         ReleaseCapture();
         SetFocus(window);
         if (select_on_mouse_up) {
-          int view_index = GetViewIndexFromMouseEvent(window, l_param);
+          int view_index = GetViewIndexFromPoint(window, gfx::Point(l_param));
           if (view_index != -1)
             table_view->Select(table_view->view_to_model(view_index));
         }
@@ -650,7 +650,7 @@ LRESULT CALLBACK TableView::TableWndProc(HWND window,
         if (in_mouse_down)
           return 0;
 
-        int view_index = GetViewIndexFromMouseEvent(window, l_param);
+        int view_index = GetViewIndexFromPoint(window, gfx::Point(l_param));
         if (view_index != -1) {
           table_view->ignore_listview_change_ = true;
           in_mouse_down = true;
@@ -791,12 +791,10 @@ HWND TableView::CreateNativeControl(HWND parent_container) {
                                 0, 0, width(), height(),
                                 parent_container, NULL, NULL, NULL);
 
-  // Make the selection extend across the row.
-  // Reduce overdraw/flicker artifacts by double buffering.
-  DWORD list_view_style = LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER;
-  if (table_type_ == CHECK_BOX_AND_TEXT)
-    list_view_style |= LVS_EX_CHECKBOXES;
-  ListView_SetExtendedListViewStyleEx(list_view_, 0, list_view_style);
+  // Reduce overdraw/flicker artifacts by double buffering.  Make the selection
+  // extend across the row.
+  ListView_SetExtendedListViewStyle(list_view_,
+                                    LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT);
   l10n_util::AdjustUIFontForWindow(list_view_);
 
   // Add the columns.
@@ -1024,7 +1022,7 @@ LRESULT TableView::OnNotify(int w_param, LPNMHDR hdr) {
 
     case LVN_ITEMCHANGED: {
       // Notification that the state of an item has changed. The state
-      // includes such things as whether the item is selected or checked.
+      // includes such things as whether the item is selected.
       NMLISTVIEW* state_change = reinterpret_cast<NMLISTVIEW*>(hdr);
       if ((state_change->uChanged & LVIF_STATE) != 0) {
         if ((state_change->uOldState & LVIS_SELECTED) !=
@@ -1032,15 +1030,6 @@ LRESULT TableView::OnNotify(int w_param, LPNMHDR hdr) {
           // Selected state of the item changed.
           OnSelectedStateChanged();
         }
-        if ((state_change->uOldState & LVIS_STATEIMAGEMASK) !=
-            (state_change->uNewState & LVIS_STATEIMAGEMASK)) {
-          // Checked state of the item changed.
-          bool is_checked =
-            ((state_change->uNewState & LVIS_STATEIMAGEMASK) ==
-             INDEXTOSTATEIMAGEMASK(2));
-          OnCheckedStateChanged(view_to_model(state_change->iItem),
-                                is_checked);
-        }
       }
       break;
     }
@@ -1369,14 +1358,10 @@ void TableView::UpdateListViewCache0(int start, int length, bool add) {
   }
 
   LVITEM item = {0};
-  int start_column = 0;
-  int max_row = start + length;
-  const bool has_groups = model_->HasGroups();
   if (add) {
-    if (has_groups)
-      item.mask = LVIF_GROUPID;
-    item.mask |= LVIF_PARAM;
-    for (int i = start; i < max_row; ++i) {
+    const bool has_groups = model_->HasGroups();
+    item.mask = has_groups ? (LVIF_GROUPID | LVIF_PARAM) : LVIF_PARAM;
+    for (int i = start; i < start + length; ++i) {
       item.iItem = i;
       if (has_groups)
         item.iGroupId = model_->GetGroupID(i);
@@ -1386,38 +1371,18 @@ void TableView::UpdateListViewCache0(int start, int length, bool add) {
   }
 
   memset(&item, 0, sizeof(LVITEM));
-
-  // NOTE: I don't quite get why the iSubItem in the following is not offset
-  // by 1. According to the docs it should be offset by one, but that doesn't
-  // work.
-  if (table_type_ == CHECK_BOX_AND_TEXT) {
-    start_column = 1;
-    item.iSubItem = 0;
-    item.mask = LVIF_TEXT | LVIF_STATE;
-    item.stateMask = LVIS_STATEIMAGEMASK;
-    for (int i = start; i < max_row; ++i) {
-      std::wstring text = model_->GetText(i, visible_columns_[0]);
-      item.iItem = add ? i : model_to_view(i);
-      item.pszText = const_cast<LPWSTR>(text.c_str());
-      item.state = INDEXTOSTATEIMAGEMASK(model_->IsChecked(i) ? 2 : 1);
-      ListView_SetItem(list_view_, &item);
-    }
-  }
-
+  item.mask =
+      (table_type_ == ICON_AND_TEXT) ? (LVIF_IMAGE | LVIF_TEXT) : LVIF_TEXT;
   item.stateMask = 0;
-  item.mask = LVIF_TEXT;
-  if (table_type_ == ICON_AND_TEXT) {
-    item.mask |= LVIF_IMAGE;
-  }
-  for (int j = start_column; j < column_count_; ++j) {
+  for (int j = 0; j < column_count_; ++j) {
     TableColumn& col = all_columns_[visible_columns_[j]];
     int max_text_width = ListView_GetStringWidth(list_view_, col.title.c_str());
-    for (int i = start; i < max_row; ++i) {
+    for (int i = start; i < start + length; ++i) {
+      // Set item.
       item.iItem = add ? i : model_to_view(i);
       item.iSubItem = j;
       std::wstring text = model_->GetText(i, visible_columns_[j]);
       item.pszText = const_cast<LPWSTR>(text.c_str());
-      item.iImage = 0;
       ListView_SetItem(list_view_, &item);
 
       // Compute width in px, using current font.
@@ -1472,11 +1437,6 @@ bool TableView::OnKeyDown(base::KeyboardCode virtual_keycode) {
   return false;  // Let the key event be processed as ususal.
 }
 
-void TableView::OnCheckedStateChanged(int model_row, bool is_checked) {
-  if (!ignore_listview_change_)
-    model_->SetChecked(model_row, is_checked);
-}
-
 int TableView::PreviousSelectedViewIndex(int view_index) {
   DCHECK_GE(view_index, 0);
   if (!list_view_ || view_index <= 0)
diff --git a/views/controls/table/table_view.h b/views/controls/table/table_view.h
index 0ed3396..ceade30 100644
--- a/views/controls/table/table_view.h
+++ b/views/controls/table/table_view.h
@@ -375,10 +375,6 @@ class TableView : public NativeControl,
   // range start - [start + length] are updated from the model.
   void UpdateListViewCache0(int start, int length, bool add);
 
-  // Notification from the ListView that the checked state of the item has
-  // changed.
-  void OnCheckedStateChanged(int model_row, bool is_checked);
-
   // Returns the index of the selected item before |view_index|, or -1 if
   // |view_index| is the first selected item.
   //
diff --git a/views/controls/table/table_view_unittest.cc b/views/controls/table/table_view_unittest.cc
index ed69be4..1a3d823 100644
--- a/views/controls/table/table_view_unittest.cc
+++ b/views/controls/table/table_view_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
 
@@ -35,11 +35,6 @@ class TestTableModel : public TableModel {
  public:
   TestTableModel();
 
-  struct CheckNotification {
-    int row;
-    bool state;
-  };
-
   // Adds a new row at index |row| with values |c1_value| and |c2_value|.
   void AddRow(int row, int c1_value, int c2_value);
 
@@ -54,11 +49,6 @@ class TestTableModel : public TableModel {
   virtual std::wstring GetText(int row, int column_id);
   virtual void SetObserver(TableModelObserver* observer);
   virtual int CompareValues(int row1, int row2, int column_id);
-  virtual bool IsChecked(int row);
-  virtual void SetChecked(int row, bool is_checked);
-
-  // Contains a record of the SetChecked calls.
-  std::vector<CheckNotification> check_notifications_;
 
  private:
   TableModelObserver* observer_;
@@ -115,16 +105,6 @@ int TestTableModel::CompareValues(int row1, int row2, int column_id) {
   return rows_[row1][column_id] - rows_[row2][column_id];
 }
 
-bool TestTableModel::IsChecked(int row) {
-  // Let's make the first row the only checked one.
-  return (row == 1);
-}
-
-void TestTableModel::SetChecked(int row, bool is_checked) {
-  CheckNotification check_notification = { row, is_checked };
-  check_notifications_.push_back(check_notification);
-}
-
 #if defined(OS_WIN)
 
 // TableViewTest ---------------------------------------------------------------
@@ -564,7 +544,7 @@ TEST_F(TableView2Test, SingleSelectionTest) {
   EXPECT_EQ(-1, table_->GetFirstSelectedRow());
 }
 
-// Row focusing and checkbox cell are not supported on Linux yet,
+// Row focusing are not supported on Linux yet.
 #if defined(OS_WIN)
 // Test the row focus on a single-selection table.
 TEST_F(TableView2Test, RowFocusTest) {
@@ -579,39 +559,4 @@ TEST_F(TableView2Test, RowFocusTest) {
   table_->ClearRowFocus();
   EXPECT_EQ(-1, table_->GetFirstSelectedRow());
 }
-
-class CheckTableView2Test : public TableView2Test {
- protected:
-  virtual views::TableTypes GetTableType() {
-    return views::CHECK_BOX_AND_TEXT;
-  }
-
-  // Sets the row check state natively.
-  void SetRowCheckState(int row, bool state) {
-#if defined(OS_WIN)
-  ListView_SetCheckState(table_->GetTestingHandle(), row, state);
-#else
-  NOTIMPLEMENTED();
-#endif
-  }
-};
-
-TEST_F(CheckTableView2Test, TestCheckTable) {
-  // Test that we were notified of the initial check states.
-  ASSERT_EQ(1U, model_->check_notifications_.size());
-  EXPECT_EQ(1, model_->check_notifications_[0].row);
-
-  // Test that we get the notification correctly.
-  model_->check_notifications_.clear();
-  SetRowCheckState(1, false);
-  SetRowCheckState(0, true);
-  SetRowCheckState(0, false);
-  ASSERT_LE(3U, model_->check_notifications_.size());
-  EXPECT_EQ(1, model_->check_notifications_[0].row);
-  EXPECT_FALSE(model_->check_notifications_[0].state);
-  EXPECT_EQ(0, model_->check_notifications_[1].row);
-  EXPECT_TRUE(model_->check_notifications_[1].state);
-  EXPECT_EQ(0, model_->check_notifications_[2].row);
-  EXPECT_FALSE(model_->check_notifications_[2].state);
-}
 #endif
-- 
cgit v1.1