summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-15 18:44:51 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-15 18:44:51 +0000
commitf941f47a837bc6d98937acc6a13603bb7c06d286 (patch)
tree50585ebe530e0a03029c84654a77658d43e27f52 /ui
parent6c32a71b9847fddb0946677ee926f88fd340691c (diff)
downloadchromium_src-f941f47a837bc6d98937acc6a13603bb7c06d286.zip
chromium_src-f941f47a837bc6d98937acc6a13603bb7c06d286.tar.gz
chromium_src-f941f47a837bc6d98937acc6a13603bb7c06d286.tar.bz2
Wires keeping the launcher up to date with the browser. I also needed GetBrowserViewForNativeWindow, so I had to wire up ViewProps for it to work correctly.
BUG=97262 TEST=none R=ben@chromium.org Review URL: http://codereview.chromium.org/8289022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105677 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/aura/window.cc5
-rw-r--r--ui/aura/window_observer.h5
-rw-r--r--ui/aura_shell/launcher/launcher.cc37
-rw-r--r--ui/aura_shell/launcher/launcher.h14
-rw-r--r--ui/aura_shell/launcher/launcher_model.cc16
-rw-r--r--ui/aura_shell/launcher/launcher_model.h9
-rw-r--r--ui/aura_shell/launcher/launcher_view.cc13
-rw-r--r--ui/gfx/compositor/layer.h1
-rw-r--r--ui/ui.gyp4
9 files changed, 90 insertions, 14 deletions
diff --git a/ui/aura/window.cc b/ui/aura/window.cc
index b14f2f3..9fa858e 100644
--- a/ui/aura/window.cc
+++ b/ui/aura/window.cc
@@ -389,6 +389,9 @@ internal::RootWindow* Window::GetRoot() {
}
void Window::SetVisible(bool visible) {
+ if (visible == layer_->visible())
+ return; // No change.
+
bool was_visible = IsVisible();
layer_->SetVisible(visible);
bool is_visible = IsVisible();
@@ -397,6 +400,8 @@ void Window::SetVisible(bool visible) {
if (delegate_)
delegate_->OnWindowVisibilityChanged(is_visible);
}
+ FOR_EACH_OBSERVER(WindowObserver, observers_,
+ OnWindowVisibilityChanged(this, is_visible));
}
void Window::SchedulePaint() {
diff --git a/ui/aura/window_observer.h b/ui/aura/window_observer.h
index fd71a5f..224f0d0 100644
--- a/ui/aura/window_observer.h
+++ b/ui/aura/window_observer.h
@@ -20,6 +20,11 @@ class AURA_EXPORT WindowObserver {
// Invoked prior to removing |window|.
virtual void OnWillRemoveWindow(Window* window) {}
+ // Invoked when the SetVisible() is invoked on a window. |visible| is the
+ // value supplied to SetVisible(). If |visible| is true, window->IsVisible()
+ // may still return false. See description in Window::IsVisible() for details.
+ virtual void OnWindowVisibilityChanged(Window* window, bool visibile) {}
+
protected:
virtual ~WindowObserver() {}
};
diff --git a/ui/aura_shell/launcher/launcher.cc b/ui/aura_shell/launcher/launcher.cc
index 5cb6a13..d2551cd 100644
--- a/ui/aura_shell/launcher/launcher.cc
+++ b/ui/aura_shell/launcher/launcher.cc
@@ -43,25 +43,44 @@ Launcher::~Launcher() {
window_container_->RemoveObserver(this);
}
-void Launcher::OnWindowAdded(aura::Window* new_window) {
+void Launcher::MaybeAdd(aura::Window* window) {
+ if (known_windows_[window] == true)
+ return; // We already tried to add this window.
+
+ known_windows_[window] = true;
ShellDelegate* delegate = Shell::GetInstance()->delegate();
if (!delegate)
return;
LauncherItem item;
- item.window = new_window;
+ item.window = window;
if (!delegate->ConfigureLauncherItem(&item))
return; // The delegate doesn't want to show this item in the launcher.
model_->Add(model_->items().size(), item);
}
+void Launcher::OnWindowAdded(aura::Window* new_window) {
+ DCHECK(known_windows_.find(new_window) == known_windows_.end());
+ known_windows_[new_window] = false;
+ new_window->AddObserver(this);
+ // Windows are created initially invisible. Wait until the window is made
+ // visible before asking, as othewise the delegate likely doesn't know about
+ // window (it's still creating it).
+ if (new_window->IsVisible())
+ MaybeAdd(new_window);
+}
+
void Launcher::OnWillRemoveWindow(aura::Window* window) {
- const LauncherItems& items(model_->items());
- for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) {
- if (i->window == window) {
- model_->RemoveItemAt(i - items.begin());
- break;
- }
- }
+ window->RemoveObserver(this);
+ known_windows_.erase(window);
+ LauncherItems::const_iterator i = model_->ItemByWindow(window);
+ if (i != model_->items().end())
+ model_->RemoveItemAt(i - model_->items().begin());
+}
+
+void Launcher::OnWindowVisibilityChanged(aura::Window* window,
+ bool visibile) {
+ if (visibile && !known_windows_[window])
+ MaybeAdd(window);
}
} // namespace aura_shell
diff --git a/ui/aura_shell/launcher/launcher.h b/ui/aura_shell/launcher/launcher.h
index 0dda152..a1c97de 100644
--- a/ui/aura_shell/launcher/launcher.h
+++ b/ui/aura_shell/launcher/launcher.h
@@ -6,6 +6,8 @@
#define UI_AURA_SHELL_LAUNCHER_LAUNCHER_H_
#pragma once
+#include <map>
+
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "ui/aura/window_observer.h"
@@ -32,9 +34,17 @@ class AURA_SHELL_EXPORT Launcher : public aura::WindowObserver {
views::Widget* widget() { return widget_; }
private:
+ typedef std::map<aura::Window*, bool> WindowMap;
+
+ // If necessary asks the delegate if an entry should be created in the
+ // launcher for |window|. This only asks the delegate once for a window.
+ void MaybeAdd(aura::Window* window);
+
// WindowObserver overrides:
virtual void OnWindowAdded(aura::Window* new_window) OVERRIDE;
virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE;
+ virtual void OnWindowVisibilityChanged(aura::Window* window,
+ bool visibile) OVERRIDE;
scoped_ptr<LauncherModel> model_;
@@ -43,6 +53,10 @@ class AURA_SHELL_EXPORT Launcher : public aura::WindowObserver {
aura::ToplevelWindowContainer* window_container_;
+ // The set of windows we know about. The boolean indicates whether we've asked
+ // the delegate if the window should added to the launcher.
+ WindowMap known_windows_;
+
DISALLOW_COPY_AND_ASSIGN(Launcher);
};
diff --git a/ui/aura_shell/launcher/launcher_model.cc b/ui/aura_shell/launcher/launcher_model.cc
index 43a6d00..5f4502e 100644
--- a/ui/aura_shell/launcher/launcher_model.cc
+++ b/ui/aura_shell/launcher/launcher_model.cc
@@ -4,6 +4,7 @@
#include "ui/aura_shell/launcher/launcher_model.h"
+#include "ui/aura/window.h"
#include "ui/aura_shell/launcher/launcher_model_observer.h"
namespace aura_shell {
@@ -45,6 +46,21 @@ void LauncherModel::SetAppImage(int index, const SkBitmap& image) {
LauncherItemImagesChanged(index));
}
+int LauncherModel::ItemIndexByWindow(aura::Window* window) {
+ LauncherItems::const_iterator i = ItemByWindow(window);
+ return i == items_.end() ? -1 : static_cast<int>((i - items_.begin()));
+}
+
+LauncherItems::const_iterator LauncherModel::ItemByWindow(
+ aura::Window* window) const {
+ for (LauncherItems::const_iterator i = items_.begin();
+ i != items_.end(); ++i) {
+ if (i->window == window)
+ return i;
+ }
+ return items_.end();
+}
+
void LauncherModel::AddObserver(LauncherModelObserver* observer) {
observers_.AddObserver(observer);
}
diff --git a/ui/aura_shell/launcher/launcher_model.h b/ui/aura_shell/launcher/launcher_model.h
index 242129e..579a673 100644
--- a/ui/aura_shell/launcher/launcher_model.h
+++ b/ui/aura_shell/launcher/launcher_model.h
@@ -12,8 +12,8 @@
#include "ui/aura_shell/aura_shell_export.h"
#include "ui/aura_shell/launcher/launcher_types.h"
-namespace views {
-class View;
+namespace aura {
+class Window;
}
namespace aura_shell {
@@ -36,6 +36,11 @@ class AURA_SHELL_EXPORT LauncherModel {
void SetTabbedImages(int index, const LauncherTabbedImages& images);
void SetAppImage(int index, const SkBitmap& image);
+ // Returns the index of the item with the specified window.
+ int ItemIndexByWindow(aura::Window* window);
+
+ LauncherItems::const_iterator ItemByWindow(aura::Window* window) const;
+
const LauncherItems& items() const { return items_; }
int item_count() const { return static_cast<int>(items_.size()); }
diff --git a/ui/aura_shell/launcher/launcher_view.cc b/ui/aura_shell/launcher/launcher_view.cc
index ed2f362..561b26d 100644
--- a/ui/aura_shell/launcher/launcher_view.cc
+++ b/ui/aura_shell/launcher/launcher_view.cc
@@ -123,7 +123,18 @@ void LauncherView::LauncherItemRemoved(int index) {
}
void LauncherView::LauncherItemImagesChanged(int index) {
- // TODO: implement me.
+ // TODO: implement better coordinate conversion.
+ const LauncherItem& item(model_->items()[index]);
+ if (item.type == TYPE_TABBED) {
+ TabbedLauncherButton* button =
+ static_cast<TabbedLauncherButton*>(child_at(index + 1));
+ gfx::Size pref = button->GetPreferredSize();
+ button->SetImages(item.tab_images);
+ if (pref != button->GetPreferredSize())
+ Resize();
+ else
+ button->SchedulePaint();
+ }
}
void LauncherView::ButtonPressed(views::Button* sender,
diff --git a/ui/gfx/compositor/layer.h b/ui/gfx/compositor/layer.h
index 3d63f03..c449e88 100644
--- a/ui/gfx/compositor/layer.h
+++ b/ui/gfx/compositor/layer.h
@@ -105,6 +105,7 @@ class COMPOSITOR_EXPORT Layer : public LayerAnimatorDelegate {
// Sets the visibility of the Layer. A Layer may be visible but not
// drawn. This happens if any ancestor of a Layer is not visible.
void SetVisible(bool visible);
+ bool visible() const { return visible_; }
// Returns true if this Layer is drawn. A Layer is drawn only if all ancestors
// are visible.
diff --git a/ui/ui.gyp b/ui/ui.gyp
index e69790e..e268b8e 100644
--- a/ui/ui.gyp
+++ b/ui/ui.gyp
@@ -478,8 +478,6 @@
'base/dragdrop/drop_target.cc',
'base/dragdrop/drop_target.h',
'base/dragdrop/os_exchange_data.cc',
- 'base/view_prop.cc',
- 'base/view_prop.h',
'gfx/native_theme_win.cc',
'gfx/native_theme_win.h',
],
@@ -541,6 +539,8 @@
}],
['toolkit_views==0', {
'sources!': [
+ 'base/view_prop.cc',
+ 'base/view_prop.h',
'gfx/render_text.cc',
'gfx/render_text.h',
'gfx/render_text_linux.cc',