| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/views/options/general_page_view.h" | 5 #include "chrome/browser/views/options/general_page_view.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/gfx/png_decoder.h" | 9 #include "base/gfx/png_decoder.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 general_page_view_->SetDefaultBrowserUIState(state); | 164 general_page_view_->SetDefaultBrowserUIState(state); |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 | 167 |
| 168 /////////////////////////////////////////////////////////////////////////////// | 168 /////////////////////////////////////////////////////////////////////////////// |
| 169 // CustomHomePagesTableModel | 169 // CustomHomePagesTableModel |
| 170 | 170 |
| 171 // CustomHomePagesTableModel is the model for the TableView showing the list | 171 // CustomHomePagesTableModel is the model for the TableView showing the list |
| 172 // of pages the user wants opened on startup. | 172 // of pages the user wants opened on startup. |
| 173 | 173 |
| 174 class CustomHomePagesTableModel : public views::TableModel { | 174 class CustomHomePagesTableModel : public TableModel { |
| 175 public: | 175 public: |
| 176 explicit CustomHomePagesTableModel(Profile* profile); | 176 explicit CustomHomePagesTableModel(Profile* profile); |
| 177 virtual ~CustomHomePagesTableModel() {} | 177 virtual ~CustomHomePagesTableModel() {} |
| 178 | 178 |
| 179 // Sets the set of urls that this model contains. | 179 // Sets the set of urls that this model contains. |
| 180 void SetURLs(const std::vector<GURL>& urls); | 180 void SetURLs(const std::vector<GURL>& urls); |
| 181 | 181 |
| 182 // Adds an entry at the specified index. | 182 // Adds an entry at the specified index. |
| 183 void Add(int index, const GURL& url); | 183 void Add(int index, const GURL& url); |
| 184 | 184 |
| 185 // Removes the entry at the specified index. | 185 // Removes the entry at the specified index. |
| 186 void Remove(int index); | 186 void Remove(int index); |
| 187 | 187 |
| 188 // Returns the set of urls this model contains. | 188 // Returns the set of urls this model contains. |
| 189 std::vector<GURL> GetURLs(); | 189 std::vector<GURL> GetURLs(); |
| 190 | 190 |
| 191 // views::TableModel overrides: | 191 // TableModel overrides: |
| 192 virtual int RowCount(); | 192 virtual int RowCount(); |
| 193 virtual std::wstring GetText(int row, int column_id); | 193 virtual std::wstring GetText(int row, int column_id); |
| 194 virtual SkBitmap GetIcon(int row); | 194 virtual SkBitmap GetIcon(int row); |
| 195 virtual void SetObserver(views::TableModelObserver* observer); | 195 virtual void SetObserver(TableModelObserver* observer); |
| 196 | 196 |
| 197 private: | 197 private: |
| 198 // Each item in the model is represented as an Entry. Entry stores the URL | 198 // Each item in the model is represented as an Entry. Entry stores the URL |
| 199 // and favicon of the page. | 199 // and favicon of the page. |
| 200 struct Entry { | 200 struct Entry { |
| 201 Entry() : fav_icon_handle(0) {} | 201 Entry() : fav_icon_handle(0) {} |
| 202 | 202 |
| 203 // URL of the page. | 203 // URL of the page. |
| 204 GURL url; | 204 GURL url; |
| 205 | 205 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 229 | 229 |
| 230 // Set of entries we're showing. | 230 // Set of entries we're showing. |
| 231 std::vector<Entry> entries_; | 231 std::vector<Entry> entries_; |
| 232 | 232 |
| 233 // Default icon to show when one can't be found for the URL. | 233 // Default icon to show when one can't be found for the URL. |
| 234 static SkBitmap default_favicon_; | 234 static SkBitmap default_favicon_; |
| 235 | 235 |
| 236 // Profile used to load icons. | 236 // Profile used to load icons. |
| 237 Profile* profile_; | 237 Profile* profile_; |
| 238 | 238 |
| 239 views::TableModelObserver* observer_; | 239 TableModelObserver* observer_; |
| 240 | 240 |
| 241 // Used in loading favicons. | 241 // Used in loading favicons. |
| 242 CancelableRequestConsumer fav_icon_consumer_; | 242 CancelableRequestConsumer fav_icon_consumer_; |
| 243 | 243 |
| 244 DISALLOW_COPY_AND_ASSIGN(CustomHomePagesTableModel); | 244 DISALLOW_COPY_AND_ASSIGN(CustomHomePagesTableModel); |
| 245 }; | 245 }; |
| 246 | 246 |
| 247 // static | 247 // static |
| 248 SkBitmap CustomHomePagesTableModel::default_favicon_; | 248 SkBitmap CustomHomePagesTableModel::default_favicon_; |
| 249 | 249 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 return net::FormatUrl(entries_[row].url, languages); | 310 return net::FormatUrl(entries_[row].url, languages); |
| 311 } | 311 } |
| 312 | 312 |
| 313 SkBitmap CustomHomePagesTableModel::GetIcon(int row) { | 313 SkBitmap CustomHomePagesTableModel::GetIcon(int row) { |
| 314 DCHECK(row >= 0 && row < RowCount()); | 314 DCHECK(row >= 0 && row < RowCount()); |
| 315 if (!entries_[row].icon.isNull()) | 315 if (!entries_[row].icon.isNull()) |
| 316 return entries_[row].icon; | 316 return entries_[row].icon; |
| 317 return default_favicon_; | 317 return default_favicon_; |
| 318 } | 318 } |
| 319 | 319 |
| 320 void CustomHomePagesTableModel::SetObserver( | 320 void CustomHomePagesTableModel::SetObserver(TableModelObserver* observer) { |
| 321 views::TableModelObserver* observer) { | |
| 322 observer_ = observer; | 321 observer_ = observer; |
| 323 } | 322 } |
| 324 | 323 |
| 325 void CustomHomePagesTableModel::InitClass() { | 324 void CustomHomePagesTableModel::InitClass() { |
| 326 static bool initialized = false; | 325 static bool initialized = false; |
| 327 if (!initialized) { | 326 if (!initialized) { |
| 328 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 327 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 329 default_favicon_ = *rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); | 328 default_favicon_ = *rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); |
| 330 initialized = true; | 329 initialized = true; |
| 331 } | 330 } |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 startup_add_custom_page_button_ = new views::NativeButton( | 790 startup_add_custom_page_button_ = new views::NativeButton( |
| 792 this, l10n_util::GetString(IDS_OPTIONS_STARTUP_ADD_BUTTON)); | 791 this, l10n_util::GetString(IDS_OPTIONS_STARTUP_ADD_BUTTON)); |
| 793 startup_remove_custom_page_button_ = new views::NativeButton( | 792 startup_remove_custom_page_button_ = new views::NativeButton( |
| 794 this, l10n_util::GetString(IDS_OPTIONS_STARTUP_REMOVE_BUTTON)); | 793 this, l10n_util::GetString(IDS_OPTIONS_STARTUP_REMOVE_BUTTON)); |
| 795 startup_remove_custom_page_button_->SetEnabled(false); | 794 startup_remove_custom_page_button_->SetEnabled(false); |
| 796 startup_use_current_page_button_ = new views::NativeButton( | 795 startup_use_current_page_button_ = new views::NativeButton( |
| 797 this, l10n_util::GetString(IDS_OPTIONS_STARTUP_USE_CURRENT)); | 796 this, l10n_util::GetString(IDS_OPTIONS_STARTUP_USE_CURRENT)); |
| 798 | 797 |
| 799 startup_custom_pages_table_model_.reset( | 798 startup_custom_pages_table_model_.reset( |
| 800 new CustomHomePagesTableModel(profile())); | 799 new CustomHomePagesTableModel(profile())); |
| 801 std::vector<views::TableColumn> columns; | 800 std::vector<TableColumn> columns; |
| 802 columns.push_back(views::TableColumn()); | 801 columns.push_back(TableColumn()); |
| 803 startup_custom_pages_table_ = new views::TableView( | 802 startup_custom_pages_table_ = new views::TableView( |
| 804 startup_custom_pages_table_model_.get(), columns, | 803 startup_custom_pages_table_model_.get(), columns, |
| 805 views::ICON_AND_TEXT, true, false, true); | 804 views::ICON_AND_TEXT, true, false, true); |
| 806 // URLs are inherently left-to-right, so do not mirror the table. | 805 // URLs are inherently left-to-right, so do not mirror the table. |
| 807 startup_custom_pages_table_->EnableUIMirroringForRTLLanguages(false); | 806 startup_custom_pages_table_->EnableUIMirroringForRTLLanguages(false); |
| 808 startup_custom_pages_table_->SetObserver(this); | 807 startup_custom_pages_table_->SetObserver(this); |
| 809 | 808 |
| 810 using views::GridLayout; | 809 using views::GridLayout; |
| 811 using views::ColumnSet; | 810 using views::ColumnSet; |
| 812 | 811 |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 homepage_use_url_textfield_->SetEnabled(false); | 1084 homepage_use_url_textfield_->SetEnabled(false); |
| 1086 homepage_use_url_textfield_->SetReadOnly(true); | 1085 homepage_use_url_textfield_->SetReadOnly(true); |
| 1087 } | 1086 } |
| 1088 } | 1087 } |
| 1089 | 1088 |
| 1090 void GeneralPageView::SetDefaultSearchProvider() { | 1089 void GeneralPageView::SetDefaultSearchProvider() { |
| 1091 const int index = default_search_engine_combobox_->selected_item(); | 1090 const int index = default_search_engine_combobox_->selected_item(); |
| 1092 default_search_engines_model_->model()->SetDefaultSearchProvider( | 1091 default_search_engines_model_->model()->SetDefaultSearchProvider( |
| 1093 default_search_engines_model_->GetTemplateURLAt(index)); | 1092 default_search_engines_model_->GetTemplateURLAt(index)); |
| 1094 } | 1093 } |
| OLD | NEW |