Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: chrome/browser/ui/aura/launcher_icon_updater.cc

Issue 8289022: Wires keeping the launcher up to date with the browser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tweaks Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/aura/launcher_icon_updater.h"
6
7 #include <algorithm>
8
9 #include "chrome/browser/favicon/favicon_tab_helper.h"
10 #include "chrome/browser/tabs/tab_strip_model.h"
11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
12 #include "grit/ui_resources.h"
13 #include "ui/aura_shell/launcher/launcher_model.h"
14 #include "ui/aura/window.h"
15 #include "ui/base/resource/resource_bundle.h"
16
17 // Max number of tabs we'll send icons over for.
18 const size_t kMaxCount = 3;
19
20 LauncherIconUpdater::LauncherIconUpdater(
21 TabStripModel* tab_model,
22 aura_shell::LauncherModel* launcher_model,
23 aura::Window* window)
24 : tab_model_(tab_model),
25 launcher_model_(launcher_model),
26 window_(window) {
27 tab_model->AddObserver(this);
28 if (tab_model->GetActiveTabContents())
29 tabs_.push_front(tab_model->GetActiveTabContents());
30 for (int i = 0; i < tab_model->count(); ++i) {
31 if (i != tab_model->active_index())
32 tabs_.push_back(tab_model->GetTabContentsAt(i));
33 }
34 UpdateLauncher();
35 }
36
37 LauncherIconUpdater::~LauncherIconUpdater() {
38 tab_model_->RemoveObserver(this);
39 }
40
41 void LauncherIconUpdater::TabInsertedAt(TabContentsWrapper* contents,
42 int index,
43 bool foreground) {
44 if (std::find(tabs_.begin(), tabs_.end(), contents) == tabs_.end())
45 tabs_.push_back(contents);
46 }
47
48 void LauncherIconUpdater::TabDetachedAt(TabContentsWrapper* contents,
49 int index) {
50 Tabs::iterator i = std::find(tabs_.begin(), tabs_.end(), contents);
51 bool update = i != tabs_.end() ? (i - tabs_.begin()) < kMaxCount : false;
52 if (i != tabs_.end())
53 tabs_.erase(i);
54 if (update)
55 UpdateLauncher();
56 }
57
58 void LauncherIconUpdater::TabSelectionChanged(
59 TabStripModel* tab_strip_model,
60 const TabStripSelectionModel& old_model) {
61 TabContentsWrapper* tab = tab_strip_model->GetActiveTabContents();
62 if (!tab)
63 return;
64
65 Tabs::iterator i = std::find(tabs_.begin(), tabs_.end(), tab);
66 if (i == tabs_.begin())
67 return; // The active tab didn't change, ignore it.
68
69 // Move the active tab to the front.
70 if (i != tabs_.end())
71 tabs_.erase(i);
72 tabs_.push_front(tab);
73 UpdateLauncher();
74 }
75
76 void LauncherIconUpdater::TabChangedAt(
77 TabContentsWrapper* tab,
78 int index,
79 TabStripModelObserver::TabChangeType change_type) {
80 if (change_type != TabStripModelObserver::LOADING_ONLY &&
81 change_type != TabStripModelObserver::TITLE_NOT_LOADING) {
82 Tabs::iterator i = std::find(tabs_.begin(), tabs_.end(), tab);
83 if (i != tabs_.end() && (i - tabs_.begin()) < kMaxCount)
84 UpdateLauncher();
85 }
86 }
87
88 void LauncherIconUpdater::UpdateLauncher() {
89 if (tabs_.empty())
90 return; // Assume the window is going to be closed if there are no tabs.
91
92 int item_index = launcher_model_->ItemIndexByWindow(window_);
93 if (item_index == -1)
94 return;
95
96 aura_shell::LauncherTabbedImages images;
97 size_t count = std::min(kMaxCount, tabs_.size());
98 images.resize(count);
99 for (size_t i = 0; i < count; ++i) {
100 // TODO: needs to be updated for apps.
101 images[i].image = tabs_[i]->favicon_tab_helper()->GetFavicon();
102 if (images[i].image.empty()) {
103 images[i].image = *ResourceBundle::GetSharedInstance().GetBitmapNamed(
104 IDR_DEFAULT_FAVICON);
105 }
106 images[i].user_data = tabs_[i];
107 }
108 launcher_model_->SetTabbedImages(item_index, images);
109 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/aura/launcher_icon_updater.h ('k') | chrome/browser/ui/views/frame/browser_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698