summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorjackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-18 07:21:22 +0000
committerjackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-18 07:21:22 +0000
commit7ec744bb44a15ceb8fe1a455568f4b7e9c635ca0 (patch)
tree03c3aee3e3900e7701706c00233c150be93a1a74 /apps
parentfbad5bb4be0194d3288efc3ab16cb4480f03ab33 (diff)
downloadchromium_src-7ec744bb44a15ceb8fe1a455568f4b7e9c635ca0.zip
chromium_src-7ec744bb44a15ceb8fe1a455568f4b7e9c635ca0.tar.gz
chromium_src-7ec744bb44a15ceb8fe1a455568f4b7e9c635ca0.tar.bz2
Add app.window.alphaEnabled() and onAlphaEnabledChanged.
This allows an app to determine whether a window created with "transparent_background" will work as expected. This also allows the app to detect when "transparent_background" might stop working, e.g. when Windows changes from Aero to Classic. This also fixes the bug where "transparent_background" windows created in Classic render as black rectangles. BUG=260810 Review URL: https://codereview.chromium.org/375183002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284026 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'apps')
-rw-r--r--apps/app_window.cc8
-rw-r--r--apps/app_window.h8
-rw-r--r--apps/ui/native_app_window.h4
-rw-r--r--apps/ui/views/native_app_window_views.cc13
-rw-r--r--apps/ui/views/native_app_window_views.h5
5 files changed, 33 insertions, 5 deletions
diff --git a/apps/app_window.cc b/apps/app_window.cc
index db1f543..340d54c 100644
--- a/apps/app_window.cc
+++ b/apps/app_window.cc
@@ -245,7 +245,8 @@ AppWindow::AppWindow(BrowserContext* context,
has_been_shown_(false),
can_send_events_(false),
is_hidden_(false),
- cached_always_on_top_(false) {
+ cached_always_on_top_(false),
+ requested_transparent_background_(false) {
extensions::ExtensionsBrowserClient* client =
extensions::ExtensionsBrowserClient::Get();
CHECK(!client->IsGuestSession(context) || context->IsOffTheRecord())
@@ -285,6 +286,8 @@ void AppWindow::Init(const GURL& url,
if (new_params.state == ui::SHOW_STATE_FULLSCREEN)
new_params.always_on_top = false;
+ requested_transparent_background_ = new_params.transparent_background;
+
native_app_window_.reset(delegate_->CreateNativeAppWindow(this, new_params));
popup_manager_.reset(
@@ -756,6 +759,9 @@ void AppWindow::GetSerializedState(base::DictionaryValue* properties) const {
properties->SetBoolean("maximized", native_app_window_->IsMaximized());
properties->SetBoolean("alwaysOnTop", IsAlwaysOnTop());
properties->SetBoolean("hasFrameColor", native_app_window_->HasFrameColor());
+ properties->SetBoolean("alphaEnabled",
+ requested_transparent_background_ &&
+ native_app_window_->CanHaveAlphaEnabled());
// These properties are undocumented and are to enable testing. Alpha is
// removed to
diff --git a/apps/app_window.h b/apps/app_window.h
index 9873eed..4e9403b 100644
--- a/apps/app_window.h
+++ b/apps/app_window.h
@@ -363,6 +363,11 @@ class AppWindow : public content::NotificationObserver,
// app.
void WindowEventsReady();
+ // Whether the app window wants a transparent background.
+ bool requested_transparent_background() const {
+ return requested_transparent_background_;
+ }
+
protected:
virtual ~AppWindow();
@@ -563,6 +568,9 @@ class AppWindow : public content::NotificationObserver,
// taskbar.
bool cached_always_on_top_;
+ // Whether |transparent_background| was set in the CreateParams.
+ bool requested_transparent_background_;
+
DISALLOW_COPY_AND_ASSIGN(AppWindow);
};
diff --git a/apps/ui/native_app_window.h b/apps/ui/native_app_window.h
index cde4c1d..fd0cc26 100644
--- a/apps/ui/native_app_window.h
+++ b/apps/ui/native_app_window.h
@@ -87,6 +87,10 @@ class NativeAppWindow : public ui::BaseWindow,
virtual void SetContentSizeConstraints(const gfx::Size& min_size,
const gfx::Size& max_size) = 0;
+ // Returns false if the underlying native window ignores alpha transparency
+ // when compositing.
+ virtual bool CanHaveAlphaEnabled() const = 0;
+
virtual ~NativeAppWindow() {}
};
diff --git a/apps/ui/views/native_app_window_views.cc b/apps/ui/views/native_app_window_views.cc
index 62b941d..da84d8a 100644
--- a/apps/ui/views/native_app_window_views.cc
+++ b/apps/ui/views/native_app_window_views.cc
@@ -27,14 +27,12 @@ NativeAppWindowViews::NativeAppWindowViews()
web_view_(NULL),
widget_(NULL),
frameless_(false),
- transparent_background_(false),
resizable_(false) {}
void NativeAppWindowViews::Init(AppWindow* app_window,
const AppWindow::CreateParams& create_params) {
app_window_ = app_window;
frameless_ = create_params.frame == AppWindow::FRAME_NONE;
- transparent_background_ = create_params.transparent_background;
resizable_ = create_params.resizable;
size_constraints_.set_minimum_size(
create_params.GetContentMinimumSize(gfx::Insets()));
@@ -53,6 +51,10 @@ NativeAppWindowViews::~NativeAppWindowViews() {
web_view_->SetWebContents(NULL);
}
+void NativeAppWindowViews::OnCanHaveAlphaEnabledChanged() {
+ app_window_->OnNativeWindowChanged();
+}
+
void NativeAppWindowViews::InitializeWindow(
AppWindow* app_window,
const AppWindow::CreateParams& create_params) {
@@ -260,7 +262,8 @@ void NativeAppWindowViews::OnWidgetActivationChanged(views::Widget* widget,
void NativeAppWindowViews::RenderViewCreated(
content::RenderViewHost* render_view_host) {
- if (transparent_background_) {
+ if (app_window_->requested_transparent_background() &&
+ CanHaveAlphaEnabled()) {
content::RenderWidgetHostView* view = render_view_host->GetView();
DCHECK(view);
view->SetBackgroundOpaque(false);
@@ -398,4 +401,8 @@ void NativeAppWindowViews::SetContentSizeConstraints(
size_constraints_.set_maximum_size(max_size);
}
+bool NativeAppWindowViews::CanHaveAlphaEnabled() const {
+ return widget_->IsTranslucentWindowOpacitySupported();
+}
+
} // namespace apps
diff --git a/apps/ui/views/native_app_window_views.h b/apps/ui/views/native_app_window_views.h
index bdebfde..917feca 100644
--- a/apps/ui/views/native_app_window_views.h
+++ b/apps/ui/views/native_app_window_views.h
@@ -52,6 +52,9 @@ class NativeAppWindowViews : public NativeAppWindow,
void Init(AppWindow* app_window,
const AppWindow::CreateParams& create_params);
+ // Signal that CanHaveTransparentBackground has changed.
+ void OnCanHaveAlphaEnabledChanged();
+
views::Widget* widget() { return widget_; }
void set_window_for_testing(views::Widget* window) { widget_ = window; }
@@ -156,6 +159,7 @@ class NativeAppWindowViews : public NativeAppWindow,
virtual gfx::Size GetContentMaximumSize() const OVERRIDE;
virtual void SetContentSizeConstraints(const gfx::Size& min_size,
const gfx::Size& max_size) OVERRIDE;
+ virtual bool CanHaveAlphaEnabled() const OVERRIDE;
// web_modal::WebContentsModalDialogHost implementation.
virtual gfx::NativeView GetHostView() const OVERRIDE;
@@ -177,7 +181,6 @@ class NativeAppWindowViews : public NativeAppWindow,
scoped_ptr<SkRegion> draggable_region_;
bool frameless_;
- bool transparent_background_;
bool resizable_;
apps::SizeConstraints size_constraints_;