Chromium Code Reviews| Index: chrome/browser/ui/panels/panel_browser_window_gtk.cc |
| diff --git a/chrome/browser/ui/panels/panel_browser_window_gtk.cc b/chrome/browser/ui/panels/panel_browser_window_gtk.cc |
| index d6461451f22d11be0b80bf688d5f647cd6c9b831..d72332e4a35ea43ad066d795313bb25561bc9bf2 100644 |
| --- a/chrome/browser/ui/panels/panel_browser_window_gtk.cc |
| +++ b/chrome/browser/ui/panels/panel_browser_window_gtk.cc |
| @@ -8,6 +8,7 @@ |
| #include "chrome/browser/ui/browser_list.h" |
| #include "chrome/browser/ui/gtk/browser_titlebar.h" |
| #include "chrome/browser/ui/gtk/custom_button.h" |
| +#include "chrome/browser/ui/gtk/theme_service_gtk.h" |
| #include "chrome/browser/ui/panels/panel.h" |
| #include "chrome/browser/ui/panels/panel_bounds_animation.h" |
| #include "chrome/browser/ui/panels/panel_browser_titlebar_gtk.h" |
| @@ -16,27 +17,78 @@ |
| #include "chrome/browser/ui/panels/panel_strip.h" |
| #include "chrome/common/chrome_notification_types.h" |
| #include "content/public/browser/notification_service.h" |
| +#include "grit/theme_resources_standard.h" |
| +#include "third_party/skia/include/core/SkShader.h" |
| +#include "ui/gfx/canvas.h" |
| +#include "ui/gfx/image/cairo_cached_surface.h" |
| +#include "ui/gfx/image/image.h" |
| +#include "ui/gfx/skia_util.h" |
| using content::WebContents; |
| namespace { |
| -// RGB values for titlebar in draw attention state. A shade of orange. |
| -const int kDrawAttentionR = 0xfa; |
| -const int kDrawAttentionG = 0x98; |
| -const int kDrawAttentionB = 0x3a; |
| -const float kDrawAttentionRFraction = kDrawAttentionR / 255.0; |
| -const float kDrawAttentionGFraction = kDrawAttentionG / 255.0; |
| -const float kDrawAttentionBFraction = kDrawAttentionB / 255.0; |
| +// Colors used to draw active titlebar under default theme. |
|
jennb
2012/04/27 18:36:13
active titlebar and frame
jianli
2012/04/27 20:22:34
Done.
|
| +const SkColor kActiveBackgroundDefaultColorStart = 0xfff0f8fa; |
|
dcheng
2012/04/27 01:18:39
Consider using SkColorSetARGB.
jianli
2012/04/27 20:22:34
Done.
|
| +const SkColor kActiveBackgroundDefaultColorEnd = 0xffc1d2dd; |
| -// Markup for title text in draw attention state. Set to color white. |
| -const char* const kDrawAttentionTitleMarkupPrefix = |
| - "<span fgcolor='#ffffff'>"; |
| -const char* const kDrawAttentionTitleMarkupSuffix = "</span>"; |
| +// Colors used to draw inactive titlebar under default theme. |
|
jennb
2012/04/27 18:36:13
titlebar and frame
jianli
2012/04/27 20:22:34
Done.
|
| +const SkColor kInactiveBackgroundDefaultColorStart = 0xffffffff; |
| +const SkColor kInactiveBackgroundDefaultColorEnd = 0xffe7edf1; |
| + |
| +// Colors used to draw titlebar for drawing attention under default theme. |
|
jennb
2012/04/27 18:36:13
titlebar and frame
jianli
2012/04/27 20:22:34
Done.
|
| +// It is also used in non-default theme since attention color is not defined |
| +// in the theme. |
| +const SkColor kAttentionBackgroundDefaultColorStart = 0xffffab57; |
| +const SkColor kAttentionBackgroundDefaultColorEnd = 0xffffab57; |
| // Set minimium width for window really small. |
| const int kMinWindowWidth = 26; |
| +gfx::Image* CreateGradientImage(SkColor start_color, SkColor end_color) { |
| + // Though the height of titlebar, used for creating gradient, cannot be |
| + // pre-determined, we use a reasonablly bigger value that should work for |
| + // most of cases. |
| + const int gradient_size = 32; |
|
jennb
2012/04/27 18:36:13
How did you decide on this number?
jianli
2012/04/27 20:22:34
Added comment to explain this.
|
| + SkShader* shader = gfx::CreateGradientShader( |
| + 0, gradient_size, start_color, end_color); |
| + SkPaint paint; |
| + paint.setStyle(SkPaint::kFill_Style); |
| + paint.setAntiAlias(true); |
| + paint.setShader(shader); |
| + shader->unref(); |
| + gfx::Canvas canvas(gfx::Size(1, gradient_size), true); |
| + canvas.DrawRect(gfx::Rect(0, 0, 1, gradient_size), paint); |
| + return new gfx::Image(new SkBitmap(canvas.ExtractBitmap())); |
|
dcheng
2012/04/27 01:18:39
I think you can just do gfx::Image(canvas.ExtractB
jianli
2012/04/27 20:22:34
Done.
|
| +} |
| + |
| +gfx::Image* GetActiveBackgroundDefaultImage() { |
| + static gfx::Image* image = NULL; |
| + if (!image) { |
| + image = CreateGradientImage(kActiveBackgroundDefaultColorStart, |
| + kActiveBackgroundDefaultColorEnd); |
| + } |
| + return image; |
| +} |
| + |
| +gfx::Image* GetInactiveBackgroundDefaultImage() { |
| + static gfx::Image* image = NULL; |
| + if (!image) { |
| + image = CreateGradientImage(kInactiveBackgroundDefaultColorStart, |
| + kInactiveBackgroundDefaultColorEnd); |
| + } |
| + return image; |
| +} |
| + |
| +gfx::Image* GetAttentionBackgroundDefaultImage() { |
| + static gfx::Image* image = NULL; |
| + if (!image) { |
| + image = CreateGradientImage(kAttentionBackgroundDefaultColorStart, |
| + kAttentionBackgroundDefaultColorEnd); |
| + } |
| + return image; |
| +} |
| + |
| } // namespace |
| NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel, |
| @@ -88,6 +140,10 @@ BrowserTitlebar* PanelBrowserWindowGtk::CreateBrowserTitlebar() { |
| return new PanelBrowserTitlebarGtk(this, window()); |
| } |
| +PanelBrowserTitlebarGtk* PanelBrowserWindowGtk::GetTitlebar() const { |
| + return static_cast<PanelBrowserTitlebarGtk*>(titlebar()); |
| +} |
| + |
| bool PanelBrowserWindowGtk::GetWindowEdge(int x, int y, GdkWindowEdge* edge) { |
| // Only detect the window edge when panels can be resized by the user. |
| // This method is used by the base class to detect when the cursor has |
| @@ -172,6 +228,10 @@ void PanelBrowserWindowGtk::SetBounds(const gfx::Rect& bounds) { |
| DLOG(WARNING) << "Unexpected call to PanelBrowserWindowGtk::SetBounds()"; |
| } |
| +bool PanelBrowserWindowGtk::IsMinimized() const { |
|
jennb
2012/04/27 18:36:13
So confusing... Usually, Panel delegates to native
jianli
2012/04/27 20:22:34
Removed.
|
| + return panel_->IsMinimized(); |
| +} |
| + |
| void PanelBrowserWindowGtk::OnSizeChanged(int width, int height) { |
| BrowserWindowGtk::OnSizeChanged(width, height); |
| @@ -198,49 +258,49 @@ void PanelBrowserWindowGtk::OnSizeChanged(int width, int height) { |
| bool PanelBrowserWindowGtk::UseCustomFrame() { |
| // We always use custom frame for panels. |
| - return TRUE; |
| + return true; |
| +} |
| + |
| +bool PanelBrowserWindowGtk::UsingCustomPopupFrame() const { |
| + // We do not draw custom popup frame. |
| + return false; |
| } |
| void PanelBrowserWindowGtk::DrawPopupFrame(cairo_t* cr, |
| GtkWidget* widget, |
| GdkEventExpose* event) { |
| - static_cast<PanelBrowserTitlebarGtk*>(titlebar())-> |
| - UpdateMinimizeRestoreButtonVisibility(); |
| - |
| - BrowserWindowGtk::DrawPopupFrame(cr, widget, event); |
| + NOTREACHED(); |
| +} |
| +const gfx::Image* PanelBrowserWindowGtk::GetFrameTheme() const { |
| if (is_drawing_attention_) |
| - DrawAttentionFrame(cr, widget, event); |
| -} |
| + return GetAttentionBackgroundDefaultImage(); |
| -void PanelBrowserWindowGtk::DrawCustomFrame(cairo_t* cr, |
| - GtkWidget* widget, |
| - GdkEventExpose* event) { |
| - static_cast<PanelBrowserTitlebarGtk*>(titlebar())-> |
| - UpdateMinimizeRestoreButtonVisibility(); |
| + bool is_active = IsActive(); |
| + ThemeServiceGtk* theme_provider = ThemeServiceGtk::GetFrom( |
| + browser()->profile()); |
| - BrowserWindowGtk::DrawCustomFrame(cr, widget, event); |
| + if (theme_provider->UsingDefaultTheme()) { |
| + return is_active ? GetActiveBackgroundDefaultImage() |
| + : GetInactiveBackgroundDefaultImage(); |
| + } |
| - if (is_drawing_attention_) |
| - DrawAttentionFrame(cr, widget, event); |
| + return theme_provider->GetImageNamed( |
| + is_active ? IDR_THEME_TOOLBAR : IDR_THEME_TAB_BACKGROUND); |
| } |
| -void PanelBrowserWindowGtk::DrawAttentionFrame(cairo_t* cr, |
| - GtkWidget* widget, |
| - GdkEventExpose* event) { |
| - cairo_set_source_rgb(cr, kDrawAttentionRFraction, |
| - kDrawAttentionGFraction, |
| - kDrawAttentionBFraction); |
| - |
| - GdkRectangle dest_rectangle = GetTitlebarRectForDrawAttention(); |
| - GdkRegion* dest_region = gdk_region_rectangle(&dest_rectangle); |
| +void PanelBrowserWindowGtk::DrawCustomFrame(cairo_t* cr, |
| + GtkWidget* widget, |
| + GdkEventExpose* event) { |
| + GetTitlebar()->UpdateMinimizeRestoreButtonVisibility(); |
| - gdk_region_intersect(dest_region, event->region); |
| - gdk_cairo_region(cr, dest_region); |
| + gfx::CairoCachedSurface* surface = GetFrameTheme()->ToCairo(); |
| - cairo_clip(cr); |
| - cairo_paint(cr); |
| - gdk_region_destroy(dest_region); |
| + surface->SetSource(cr, widget, 0, 0); |
| + cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); |
| + cairo_rectangle(cr, event->area.x, event->area.y, |
| + event->area.width, event->area.height); |
| + cairo_fill(cr); |
| } |
| void PanelBrowserWindowGtk::ActiveWindowChanged(GdkWindow* active_window) { |
| @@ -253,27 +313,6 @@ void PanelBrowserWindowGtk::ActiveWindowChanged(GdkWindow* active_window) { |
| panel_->OnActiveStateChanged(is_active); |
| } |
| -BrowserWindowGtk::TitleDecoration PanelBrowserWindowGtk::GetWindowTitle( |
| - std::string* title) const { |
| - if (is_drawing_attention_) { |
| - std::string title_original; |
| - BrowserWindowGtk::TitleDecoration title_decoration = |
| - BrowserWindowGtk::GetWindowTitle(&title_original); |
| - DCHECK_EQ(BrowserWindowGtk::PLAIN_TEXT, title_decoration); |
| - gchar* title_escaped = g_markup_escape_text(title_original.c_str(), -1); |
| - gchar* title_with_markup = g_strconcat(kDrawAttentionTitleMarkupPrefix, |
| - title_escaped, |
| - kDrawAttentionTitleMarkupSuffix, |
| - NULL); |
| - *title = title_with_markup; |
| - g_free(title_escaped); |
| - g_free(title_with_markup); |
| - return BrowserWindowGtk::PANGO_MARKUP; |
| - } else { |
| - return BrowserWindowGtk::GetWindowTitle(title); |
| - } |
| -} |
| - |
| void PanelBrowserWindowGtk::Observe( |
| int type, |
| const content::NotificationSource& source, |
| @@ -411,11 +450,8 @@ void PanelBrowserWindowGtk::DrawAttention(bool draw_attention) { |
| is_drawing_attention_ = draw_attention; |
| - GdkRectangle rect = GetTitlebarRectForDrawAttention(); |
| - gdk_window_invalidate_rect( |
| - gtk_widget_get_window(GTK_WIDGET(window())), &rect, TRUE); |
| - |
| - UpdateTitleBar(); |
| + GetTitlebar()->UpdateTextColor(); |
| + UserChangedTheme(); |
|
jennb
2012/04/27 18:36:13
Seems like overkill. We just want to repaint the t
jianli
2012/04/27 20:22:34
Done.
|
| if ((panel_->attention_mode() & Panel::USE_SYSTEM_ATTENTION) != 0) |
| ::BrowserWindowGtk::FlashFrame(draw_attention); |
| @@ -450,9 +486,7 @@ void PanelBrowserWindowGtk::DestroyPanelBrowser() { |
| } |
| gfx::Size PanelBrowserWindowGtk::IconOnlySize() const { |
|
jennb
2012/04/27 18:36:13
go ahead and delete this obsoleted method in this
jianli
2012/04/27 20:22:34
Done.
|
| - GtkAllocation allocation; |
| - gtk_widget_get_allocation(titlebar_widget(), &allocation); |
| - return gfx::Size(titlebar()->IconOnlyWidth(), allocation.height); |
| + return gfx::Size(); |
| } |
| void PanelBrowserWindowGtk::EnsurePanelFullyVisible() { |
| @@ -505,7 +539,7 @@ bool PanelBrowserWindowGtk::IsAnimatingBounds() const { |
| } |
| void PanelBrowserWindowGtk::AnimationEnded(const ui::Animation* animation) { |
| - titlebar()->SendEnterNotifyToCloseButtonIfUnderMouse(); |
| + GetTitlebar()->SendEnterNotifyToCloseButtonIfUnderMouse(); |
| panel_->manager()->OnPanelAnimationEnded(panel_.get()); |
| } |
| @@ -523,24 +557,6 @@ void PanelBrowserWindowGtk::AnimationProgressed( |
| last_animation_progressed_bounds_ = new_bounds; |
| } |
| -GdkRectangle PanelBrowserWindowGtk::GetTitlebarRectForDrawAttention() const { |
| - GdkRectangle rect; |
| - rect.x = 0; |
| - rect.y = 0; |
| - // We get the window width and not the titlebar_widget() width because we'd |
| - // like for the window borders on either side of the title bar to be the same |
| - // color. |
| - GtkAllocation window_allocation; |
| - gtk_widget_get_allocation(GTK_WIDGET(window()), &window_allocation); |
| - rect.width = window_allocation.width; |
| - |
| - GtkAllocation titlebar_allocation; |
| - gtk_widget_get_allocation(titlebar_widget(), &titlebar_allocation); |
| - rect.height = titlebar_allocation.height; |
| - |
| - return rect; |
| -} |
| - |
| gboolean PanelBrowserWindowGtk::OnTitlebarButtonReleaseEvent( |
| GtkWidget* widget, GdkEventButton* event) { |
| if (event->button != 1) |
| @@ -650,11 +666,7 @@ void NativePanelTestingGtk::FinishDragTitlebar() { |
| } |
| bool NativePanelTestingGtk::VerifyDrawingAttention() const { |
| - std::string title; |
| - BrowserWindowGtk::TitleDecoration decoration = |
| - panel_browser_window_gtk_->GetWindowTitle(&title); |
| - return panel_browser_window_gtk_->IsDrawingAttention() && |
| - decoration == BrowserWindowGtk::PANGO_MARKUP; |
| + return panel_browser_window_gtk_->IsDrawingAttention(); |
| } |
| bool NativePanelTestingGtk::VerifyActiveState(bool is_active) { |
| @@ -679,8 +691,7 @@ bool NativePanelTestingGtk::IsAnimatingBounds() const { |
| bool NativePanelTestingGtk::IsButtonVisible( |
| TitlebarButtonType button_type) const { |
| - PanelBrowserTitlebarGtk* titlebar = static_cast<PanelBrowserTitlebarGtk*>( |
| - panel_browser_window_gtk_->titlebar()); |
| + PanelBrowserTitlebarGtk* titlebar = panel_browser_window_gtk_->GetTitlebar(); |
| CustomDrawButton* button; |
| switch (button_type) { |
| case CLOSE_BUTTON: |