[email protected] | ee2ed42c | 2011-04-28 22:19:14 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 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_CUSTOM_HOME_PAGES_TABLE_MODEL_H_ |
| 6 | #define CHROME_BROWSER_CUSTOM_HOME_PAGES_TABLE_MODEL_H_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 8 | |
| 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
[email protected] | bdaab67c | 2010-12-30 00:50:04 | [diff] [blame] | 12 | #include "base/compiler_specific.h" |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 13 | #include "chrome/browser/history/history.h" |
[email protected] | ee2ed42c | 2011-04-28 22:19:14 | [diff] [blame] | 14 | #include "chrome/browser/favicon/favicon_service.h" |
[email protected] | 44cbd9e | 2011-01-14 15:49:40 | [diff] [blame] | 15 | #include "ui/base/models/table_model.h" |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 16 | |
[email protected] | c3a4bd99 | 2010-08-18 20:25:01 | [diff] [blame] | 17 | class GURL; |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 18 | class Profile; |
[email protected] | c3a4bd99 | 2010-08-18 20:25:01 | [diff] [blame] | 19 | class SkBitmap; |
[email protected] | 44cbd9e | 2011-01-14 15:49:40 | [diff] [blame] | 20 | |
| 21 | namespace ui { |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 22 | class TableModelObserver; |
[email protected] | 44cbd9e | 2011-01-14 15:49:40 | [diff] [blame] | 23 | } |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 24 | |
| 25 | // CustomHomePagesTableModel is the model for the TableView showing the list |
| 26 | // of pages the user wants opened on startup. |
| 27 | |
[email protected] | 44cbd9e | 2011-01-14 15:49:40 | [diff] [blame] | 28 | class CustomHomePagesTableModel : public ui::TableModel { |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 29 | public: |
| 30 | explicit CustomHomePagesTableModel(Profile* profile); |
[email protected] | c3a4bd99 | 2010-08-18 20:25:01 | [diff] [blame] | 31 | virtual ~CustomHomePagesTableModel(); |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 32 | |
| 33 | // Sets the set of urls that this model contains. |
| 34 | void SetURLs(const std::vector<GURL>& urls); |
| 35 | |
[email protected] | 21c52bd | 2011-06-14 01:00:48 | [diff] [blame] | 36 | // Collect all entries indexed by |index_list|, and moves them to be right |
| 37 | // before the element addressed by |insert_before|. Used by Drag&Drop. |
| 38 | // Expects |index_list| to be ordered ascending. |
| 39 | void MoveURLs(int insert_before, const std::vector<int>& index_list); |
| 40 | |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 41 | // Adds an entry at the specified index. |
| 42 | void Add(int index, const GURL& url); |
| 43 | |
| 44 | // Removes the entry at the specified index. |
| 45 | void Remove(int index); |
| 46 | |
[email protected] | b0c5487 | 2010-05-13 02:06:55 | [diff] [blame] | 47 | // Clears any entries and fills the list with pages currently opened in the |
| 48 | // browser. |
| 49 | void SetToCurrentlyOpenPages(); |
| 50 | |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 51 | // Returns the set of urls this model contains. |
| 52 | std::vector<GURL> GetURLs(); |
| 53 | |
| 54 | // TableModel overrides: |
[email protected] | bdaab67c | 2010-12-30 00:50:04 | [diff] [blame] | 55 | virtual int RowCount() OVERRIDE; |
| 56 | virtual string16 GetText(int row, int column_id) OVERRIDE; |
| 57 | virtual SkBitmap GetIcon(int row) OVERRIDE; |
| 58 | virtual string16 GetTooltip(int row) OVERRIDE; |
[email protected] | 44cbd9e | 2011-01-14 15:49:40 | [diff] [blame] | 59 | virtual void SetObserver(ui::TableModelObserver* observer) OVERRIDE; |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 60 | |
| 61 | private: |
| 62 | // Each item in the model is represented as an Entry. Entry stores the URL, |
| 63 | // title, and favicon of the page. |
[email protected] | c3a4bd99 | 2010-08-18 20:25:01 | [diff] [blame] | 64 | struct Entry; |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 65 | |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 66 | // Loads the title and favicon for the specified entry. |
[email protected] | f16039d2 | 2011-03-16 18:54:05 | [diff] [blame] | 67 | void LoadTitleAndFavicon(Entry* entry); |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 68 | |
| 69 | // Callback from history service. Updates the title of the Entry whose |
| 70 | // |title_handle| matches |handle| and notifies the observer of the change. |
| 71 | void OnGotTitle(HistoryService::Handle handle, |
| 72 | bool found_url, |
| 73 | const history::URLRow* row, |
| 74 | history::VisitVector* visits); |
| 75 | |
| 76 | // Callback from history service. Updates the icon of the Entry whose |
[email protected] | 16be5c3 | 2011-03-15 17:52:03 | [diff] [blame] | 77 | // |favicon_handle| matches |handle| and notifies the observer of the change. |
[email protected] | f16039d2 | 2011-03-16 18:54:05 | [diff] [blame] | 78 | void OnGotFavicon(FaviconService::Handle handle, |
[email protected] | 849ccee | 2011-03-16 17:05:30 | [diff] [blame] | 79 | history::FaviconData favicon); |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 80 | |
| 81 | // Returns the entry whose |member| matches |handle| and sets |entry_index| to |
| 82 | // the index of the entry. |
| 83 | Entry* GetEntryByLoadHandle(CancelableRequestProvider::Handle Entry::* member, |
| 84 | CancelableRequestProvider::Handle handle, |
| 85 | int* entry_index); |
| 86 | |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 87 | // Returns the URL for a particular row, formatted for display to the user. |
[email protected] | bdaab67c | 2010-12-30 00:50:04 | [diff] [blame] | 88 | string16 FormattedURL(int row) const; |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 89 | |
| 90 | // Set of entries we're showing. |
| 91 | std::vector<Entry> entries_; |
| 92 | |
| 93 | // Default icon to show when one can't be found for the URL. |
[email protected] | 122b468 | 2010-07-28 20:59:12 | [diff] [blame] | 94 | SkBitmap* default_favicon_; |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 95 | |
| 96 | // Profile used to load titles and icons. |
| 97 | Profile* profile_; |
| 98 | |
[email protected] | 44cbd9e | 2011-01-14 15:49:40 | [diff] [blame] | 99 | ui::TableModelObserver* observer_; |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 100 | |
| 101 | // Used in loading titles and favicons. |
[email protected] | 9d52ae6 | 2011-06-21 04:04:19 | [diff] [blame] | 102 | CancelableRequestConsumer history_query_consumer_; |
| 103 | CancelableRequestConsumer favicon_query_consumer_; |
[email protected] | 7fff7901 | 2010-05-12 00:19:05 | [diff] [blame] | 104 | |
| 105 | DISALLOW_COPY_AND_ASSIGN(CustomHomePagesTableModel); |
| 106 | }; |
| 107 | |
| 108 | #endif // CHROME_BROWSER_CUSTOM_HOME_PAGES_TABLE_MODEL_H_ |