| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/shelf_item_dialog.h" | 5 #include "chrome/browser/views/shelf_item_dialog.h" |
| 6 | 6 |
| 7 #include "app/gfx/text_elider.h" | 7 #include "app/gfx/text_elider.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
| 10 #include "app/table_model.h" |
| 11 #include "app/table_model_observer.h" |
| 10 #include "base/gfx/png_decoder.h" | 12 #include "base/gfx/png_decoder.h" |
| 11 #include "base/stl_util-inl.h" | 13 #include "base/stl_util-inl.h" |
| 12 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 13 #include "chrome/browser/net/url_fixer_upper.h" | 15 #include "chrome/browser/net/url_fixer_upper.h" |
| 14 #include "chrome/browser/profile.h" | 16 #include "chrome/browser/profile.h" |
| 15 #include "chrome/browser/tab_contents/tab_contents.h" | 17 #include "chrome/browser/tab_contents/tab_contents.h" |
| 16 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 17 #include "chrome/common/pref_service.h" | 19 #include "chrome/common/pref_service.h" |
| 18 #include "grit/app_resources.h" | 20 #include "grit/app_resources.h" |
| 19 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
| 20 #include "grit/locale_settings.h" | 22 #include "grit/locale_settings.h" |
| 21 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
| 22 #include "views/background.h" | 24 #include "views/background.h" |
| 23 #include "views/controls/label.h" | 25 #include "views/controls/label.h" |
| 24 #include "views/controls/table/table_model.h" | |
| 25 #include "views/controls/table/table_model_observer.h" | |
| 26 #include "views/controls/table/table_view.h" | 26 #include "views/controls/table/table_view.h" |
| 27 #include "views/controls/textfield/textfield.h" | 27 #include "views/controls/textfield/textfield.h" |
| 28 #include "views/focus/focus_manager.h" | 28 #include "views/focus/focus_manager.h" |
| 29 #include "views/grid_layout.h" | 29 #include "views/grid_layout.h" |
| 30 #include "views/standard_layout.h" | 30 #include "views/standard_layout.h" |
| 31 #include "views/widget/widget.h" | 31 #include "views/widget/widget.h" |
| 32 | 32 |
| 33 using base::Time; | 33 using base::Time; |
| 34 using base::TimeDelta; | 34 using base::TimeDelta; |
| 35 using views::ColumnSet; | 35 using views::ColumnSet; |
| 36 using views::GridLayout; | 36 using views::GridLayout; |
| 37 | 37 |
| 38 // Preferred height of the table. | 38 // Preferred height of the table. |
| 39 static const int kTableWidth = 300; | 39 static const int kTableWidth = 300; |
| 40 | 40 |
| 41 // The default favicon. | 41 // The default favicon. |
| 42 static SkBitmap* default_fav_icon = NULL; | 42 static SkBitmap* default_fav_icon = NULL; |
| 43 | 43 |
| 44 //////////////////////////////////////////////////////////////////////////////// | 44 //////////////////////////////////////////////////////////////////////////////// |
| 45 // | 45 // |
| 46 // A table model to represent the list of URLS that we the user might want to | 46 // A table model to represent the list of URLS that we the user might want to |
| 47 // bookmark. | 47 // bookmark. |
| 48 // | 48 // |
| 49 //////////////////////////////////////////////////////////////////////////////// | 49 //////////////////////////////////////////////////////////////////////////////// |
| 50 | 50 |
| 51 // How long we query entry points for. | 51 // How long we query entry points for. |
| 52 static const int kPossibleURLTimeScope = 30; | 52 static const int kPossibleURLTimeScope = 30; |
| 53 | 53 |
| 54 class PossibleURLModel : public views::TableModel { | 54 class PossibleURLModel : public TableModel { |
| 55 public: | 55 public: |
| 56 PossibleURLModel() : profile_(NULL) { | 56 PossibleURLModel() : profile_(NULL) { |
| 57 if (!default_fav_icon) { | 57 if (!default_fav_icon) { |
| 58 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 58 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 59 default_fav_icon = rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); | 59 default_fav_icon = rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 virtual ~PossibleURLModel() { | 63 virtual ~PossibleURLModel() { |
| 64 } | 64 } |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 // The decoder will leave our bitmap empty on error. | 208 // The decoder will leave our bitmap empty on error. |
| 209 PNGDecoder::Decode(&data->data, &(fav_icon_map_[index])); | 209 PNGDecoder::Decode(&data->data, &(fav_icon_map_[index])); |
| 210 | 210 |
| 211 // Notify the observer. | 211 // Notify the observer. |
| 212 if (!fav_icon_map_[index].isNull() && observer_) | 212 if (!fav_icon_map_[index].isNull() && observer_) |
| 213 observer_->OnItemsChanged(static_cast<int>(index), 1); | 213 observer_->OnItemsChanged(static_cast<int>(index), 1); |
| 214 } | 214 } |
| 215 } | 215 } |
| 216 } | 216 } |
| 217 | 217 |
| 218 virtual void SetObserver(views::TableModelObserver* observer) { | 218 virtual void SetObserver(TableModelObserver* observer) { |
| 219 observer_ = observer; | 219 observer_ = observer; |
| 220 } | 220 } |
| 221 | 221 |
| 222 private: | 222 private: |
| 223 // Contains the data needed to show a result. | 223 // Contains the data needed to show a result. |
| 224 struct Result { | 224 struct Result { |
| 225 Result() : index(0) {} | 225 Result() : index(0) {} |
| 226 | 226 |
| 227 GURL url; | 227 GURL url; |
| 228 // Index of this Result in results_. This is used as the key into | 228 // Index of this Result in results_. This is used as the key into |
| 229 // fav_icon_map_ to lookup the favicon for the url, as well as the index | 229 // fav_icon_map_ to lookup the favicon for the url, as well as the index |
| 230 // into results_ when the favicon is received. | 230 // into results_ when the favicon is received. |
| 231 size_t index; | 231 size_t index; |
| 232 gfx::SortedDisplayURL display_url; | 232 gfx::SortedDisplayURL display_url; |
| 233 std::wstring title; | 233 std::wstring title; |
| 234 }; | 234 }; |
| 235 | 235 |
| 236 // The current profile. | 236 // The current profile. |
| 237 Profile* profile_; | 237 Profile* profile_; |
| 238 | 238 |
| 239 // Our observer. | 239 // Our observer. |
| 240 views::TableModelObserver* observer_; | 240 TableModelObserver* observer_; |
| 241 | 241 |
| 242 // Our consumer for favicon requests. | 242 // Our consumer for favicon requests. |
| 243 CancelableRequestConsumerT<size_t, NULL> consumer_; | 243 CancelableRequestConsumerT<size_t, NULL> consumer_; |
| 244 | 244 |
| 245 // The results we're showing. | 245 // The results we're showing. |
| 246 std::vector<Result> results_; | 246 std::vector<Result> results_; |
| 247 | 247 |
| 248 // Map Result::index -> Favicon. | 248 // Map Result::index -> Favicon. |
| 249 typedef std::map<size_t, SkBitmap> FavIconMap; | 249 typedef std::map<size_t, SkBitmap> FavIconMap; |
| 250 FavIconMap fav_icon_map_; | 250 FavIconMap fav_icon_map_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 262 bool show_title) | 262 bool show_title) |
| 263 : profile_(profile), | 263 : profile_(profile), |
| 264 expected_title_handle_(0), | 264 expected_title_handle_(0), |
| 265 delegate_(delegate) { | 265 delegate_(delegate) { |
| 266 DCHECK(profile_); | 266 DCHECK(profile_); |
| 267 | 267 |
| 268 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 268 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 269 | 269 |
| 270 url_table_model_.reset(new PossibleURLModel()); | 270 url_table_model_.reset(new PossibleURLModel()); |
| 271 | 271 |
| 272 views::TableColumn col1(IDS_ASI_PAGE_COLUMN, views::TableColumn::LEFT, -1, | 272 TableColumn col1(IDS_ASI_PAGE_COLUMN, TableColumn::LEFT, -1, |
| 273 50); | 273 50); |
| 274 col1.sortable = true; | 274 col1.sortable = true; |
| 275 views::TableColumn col2(IDS_ASI_URL_COLUMN, views::TableColumn::LEFT, -1, | 275 TableColumn col2(IDS_ASI_URL_COLUMN, TableColumn::LEFT, -1, |
| 276 50); | 276 50); |
| 277 col2.sortable = true; | 277 col2.sortable = true; |
| 278 std::vector<views::TableColumn> cols; | 278 std::vector<TableColumn> cols; |
| 279 cols.push_back(col1); | 279 cols.push_back(col1); |
| 280 cols.push_back(col2); | 280 cols.push_back(col2); |
| 281 | 281 |
| 282 url_table_ = new views::TableView(url_table_model_.get(), cols, | 282 url_table_ = new views::TableView(url_table_model_.get(), cols, |
| 283 views::ICON_AND_TEXT, true, true, | 283 views::ICON_AND_TEXT, true, true, |
| 284 true); | 284 true); |
| 285 url_table_->SetObserver(this); | 285 url_table_->SetObserver(this); |
| 286 | 286 |
| 287 // Yummy layout code. | 287 // Yummy layout code. |
| 288 const int labels_column_set_id = 0; | 288 const int labels_column_set_id = 0; |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 OnSelectionChanged(); | 522 OnSelectionChanged(); |
| 523 PerformModelChange(); | 523 PerformModelChange(); |
| 524 if (window()) | 524 if (window()) |
| 525 window()->Close(); | 525 window()->Close(); |
| 526 } | 526 } |
| 527 } | 527 } |
| 528 | 528 |
| 529 GURL ShelfItemDialog::GetInputURL() const { | 529 GURL ShelfItemDialog::GetInputURL() const { |
| 530 return GURL(URLFixerUpper::FixupURL(url_field_->text(), L"")); | 530 return GURL(URLFixerUpper::FixupURL(url_field_->text(), L"")); |
| 531 } | 531 } |
| OLD | NEW |