Commit dd85e3fe authored by oshima's avatar oshima Committed by Commit bot

Use nine image painter to draw tray background

BUG=432500

Review URL: https://codereview.chromium.org/798163003

Cr-Commit-Position: refs/heads/master@{#308484}
parent dbf5e6c0
...@@ -46,23 +46,23 @@ ...@@ -46,23 +46,23 @@
<structure type="chrome_scaled_image" name="IDR_AURA_RESIZE_SHADOW_TOP_LEFT" file="common/resize_shadow_top_left.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_RESIZE_SHADOW_TOP_LEFT" file="common/resize_shadow_top_left.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_RESIZE_SHADOW_TOP_RIGHT" file="common/resize_shadow_top_right.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_RESIZE_SHADOW_TOP_RIGHT" file="common/resize_shadow_top_right.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_HORIZ_CENTER" file="common/shelf/status_tray_normal_center.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_HORIZ_CENTER" file="common/shelf/status_tray_normal_center.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_HORIZ_CENTER_ONBLACK" file="common/shelf/status_tray_normal_onblack_center.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_HORIZ_CENTER_PRESSED" file="common/shelf/status_tray_pressed_center.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_HORIZ_LEFT" file="common/shelf/status_tray_normal_left.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_HORIZ_LEFT" file="common/shelf/status_tray_normal_left.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_HORIZ_LEFT_ONBLACK" file="common/shelf/status_tray_normal_onblack_left.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_HORIZ_ONBLACK_CENTER" file="common/shelf/status_tray_normal_onblack_center.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_HORIZ_LEFT_PRESSED" file="common/shelf/status_tray_pressed_left.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_HORIZ_ONBLACK_LEFT" file="common/shelf/status_tray_normal_onblack_left.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_HORIZ_ONBLACK_RIGHT" file="common/shelf/status_tray_normal_onblack_right.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_HORIZ_PRESSED_CENTER" file="common/shelf/status_tray_pressed_center.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_HORIZ_PRESSED_LEFT" file="common/shelf/status_tray_pressed_left.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_HORIZ_PRESSED_RIGHT" file="common/shelf/status_tray_pressed_right.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_HORIZ_RIGHT" file="common/shelf/status_tray_normal_right.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_HORIZ_RIGHT" file="common/shelf/status_tray_normal_right.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_HORIZ_RIGHT_ONBLACK" file="common/shelf/status_tray_normal_onblack_right.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_HORIZ_RIGHT_PRESSED" file="common/shelf/status_tray_pressed_right.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_VERTICAL_BOTTOM" file="common/shelf/status_tray_vertical_normal_bottom.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_VERTICAL_BOTTOM" file="common/shelf/status_tray_vertical_normal_bottom.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_VERTICAL_BOTTOM_ONBLACK" file="common/shelf/status_tray_vertical_normal_onblack_bottom.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_VERTICAL_BOTTOM_PRESSED" file="common/shelf/status_tray_vertical_pressed_bottom.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_VERTICAL_TOP" file="common/shelf/status_tray_vertical_normal_top.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_VERTICAL_TOP_ONBLACK" file="common/shelf/status_tray_vertical_normal_onblack_top.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_VERTICAL_TOP_PRESSED" file="common/shelf/status_tray_vertical_pressed_top.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_VERTICAL_CENTER" file="common/shelf/status_tray_vertical_normal_center.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_VERTICAL_CENTER" file="common/shelf/status_tray_vertical_normal_center.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_VERTICAL_CENTER_ONBLACK" file="common/shelf/status_tray_vertical_normal_onblack_center.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_VERTICAL_ONBLACK_BOTTOM" file="common/shelf/status_tray_vertical_normal_onblack_bottom.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_VERTICAL_CENTER_PRESSED" file="common/shelf/status_tray_vertical_pressed_center.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_VERTICAL_ONBLACK_CENTER" file="common/shelf/status_tray_vertical_normal_onblack_center.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_VERTICAL_ONBLACK_TOP" file="common/shelf/status_tray_vertical_normal_onblack_top.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_VERTICAL_PRESSED_BOTTOM" file="common/shelf/status_tray_vertical_pressed_bottom.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_VERTICAL_PRESSED_CENTER" file="common/shelf/status_tray_vertical_pressed_center.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_VERTICAL_PRESSED_TOP" file="common/shelf/status_tray_vertical_pressed_top.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_BG_VERTICAL_TOP" file="common/shelf/status_tray_vertical_normal_top.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER" file="common/tray_popup_label_button_border.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER" file="common/tray_popup_label_button_border.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_POPUP_LABEL_BUTTON_HOVER_BACKGROUND" file="common/tray_popup_label_button_hover_background.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_TRAY_POPUP_LABEL_BUTTON_HOVER_BACKGROUND" file="common/tray_popup_label_button_hover_background.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND" file="common/tray_popup_label_button_normal_background.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND" file="common/tray_popup_label_button_normal_background.png" />
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "ui/accessibility/ax_view_state.h" #include "ui/accessibility/ax_view_state.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h" #include "ui/aura/window_event_dispatcher.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/nine_image_painter_factory.h"
#include "ui/base/ui_base_switches_util.h" #include "ui/base/ui_base_switches_util.h"
#include "ui/compositor/layer.h" #include "ui/compositor/layer.h"
#include "ui/compositor/layer_animation_element.h" #include "ui/compositor/layer_animation_element.h"
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_operations.h" #include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/nine_image_painter.h"
#include "ui/gfx/rect.h" #include "ui/gfx/rect.h"
#include "ui/gfx/screen.h" #include "ui/gfx/screen.h"
#include "ui/gfx/skia_util.h" #include "ui/gfx/skia_util.h"
...@@ -100,53 +101,6 @@ class TrayBackground : public views::Background { ...@@ -100,53 +101,6 @@ class TrayBackground : public views::Background {
explicit TrayBackground(TrayBackgroundView* tray_background_view) : explicit TrayBackground(TrayBackgroundView* tray_background_view) :
tray_background_view_(tray_background_view) { tray_background_view_(tray_background_view) {
set_alpha(kTrayBackgroundAlpha); set_alpha(kTrayBackgroundAlpha);
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
leading_images_[kImageHorizontal][kImageTypeDefault] =
rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_LEFT).ToImageSkia();
middle_images_[kImageHorizontal][kImageTypeDefault] =
rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_CENTER).ToImageSkia();
trailing_images_[kImageHorizontal][kImageTypeDefault] =
rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_RIGHT).ToImageSkia();
leading_images_[kImageHorizontal][kImageTypeOnBlack] =
rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_LEFT_ONBLACK).ToImageSkia();
middle_images_[kImageHorizontal][kImageTypeOnBlack] =
rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_CENTER_ONBLACK).ToImageSkia();
trailing_images_[kImageHorizontal][kImageTypeOnBlack] =
rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_RIGHT_ONBLACK).ToImageSkia();
leading_images_[kImageHorizontal][kImageTypePressed] =
rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_LEFT_PRESSED).ToImageSkia();
middle_images_[kImageHorizontal][kImageTypePressed] =
rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_CENTER_PRESSED).ToImageSkia();
trailing_images_[kImageHorizontal][kImageTypePressed] =
rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_RIGHT_PRESSED).ToImageSkia();
leading_images_[kImageVertical][kImageTypeDefault] =
rb.GetImageNamed(IDR_AURA_TRAY_BG_VERTICAL_TOP).ToImageSkia();
middle_images_[kImageVertical][kImageTypeDefault] =
rb.GetImageNamed(
IDR_AURA_TRAY_BG_VERTICAL_CENTER).ToImageSkia();
trailing_images_[kImageVertical][kImageTypeDefault] =
rb.GetImageNamed(IDR_AURA_TRAY_BG_VERTICAL_BOTTOM).ToImageSkia();
leading_images_[kImageVertical][kImageTypeOnBlack] =
rb.GetImageNamed(IDR_AURA_TRAY_BG_VERTICAL_TOP_ONBLACK).ToImageSkia();
middle_images_[kImageVertical][kImageTypeOnBlack] =
rb.GetImageNamed(
IDR_AURA_TRAY_BG_VERTICAL_CENTER_ONBLACK).ToImageSkia();
trailing_images_[kImageVertical][kImageTypeOnBlack] =
rb.GetImageNamed(
IDR_AURA_TRAY_BG_VERTICAL_BOTTOM_ONBLACK).ToImageSkia();
leading_images_[kImageVertical][kImageTypePressed] =
rb.GetImageNamed(IDR_AURA_TRAY_BG_VERTICAL_TOP_PRESSED).ToImageSkia();
middle_images_[kImageVertical][kImageTypePressed] =
rb.GetImageNamed(
IDR_AURA_TRAY_BG_VERTICAL_CENTER_PRESSED).ToImageSkia();
trailing_images_[kImageVertical][kImageTypePressed] =
rb.GetImageNamed(
IDR_AURA_TRAY_BG_VERTICAL_BOTTOM_PRESSED).ToImageSkia();
} }
~TrayBackground() override {} ~TrayBackground() override {}
...@@ -163,6 +117,20 @@ class TrayBackground : public views::Background { ...@@ -163,6 +117,20 @@ class TrayBackground : public views::Background {
// Overridden from views::Background. // Overridden from views::Background.
void Paint(gfx::Canvas* canvas, views::View* view) const override { void Paint(gfx::Canvas* canvas, views::View* view) const override {
const int kGridSizeForPainter = 9;
const int kImages[kNumOrientations][kNumStates][kGridSizeForPainter] = {
{ // Horizontal
IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ),
IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ_ONBLACK),
IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ_PRESSED),
},
{ // Vertical
IMAGE_GRID_VERTICAL(IDR_AURA_TRAY_BG_VERTICAL),
IMAGE_GRID_VERTICAL(IDR_AURA_TRAY_BG_VERTICAL_ONBLACK),
IMAGE_GRID_VERTICAL(IDR_AURA_TRAY_BG_VERTICAL_PRESSED),
}
};
int orientation = kImageHorizontal; int orientation = kImageHorizontal;
ShelfWidget* shelf_widget = GetShelfWidget(); ShelfWidget* shelf_widget = GetShelfWidget();
if (shelf_widget && if (shelf_widget &&
...@@ -177,57 +145,14 @@ class TrayBackground : public views::Background { ...@@ -177,57 +145,14 @@ class TrayBackground : public views::Background {
else else
state = kImageTypeDefault; state = kImageTypeDefault;
const gfx::ImageSkia* leading = leading_images_[orientation][state]; ui::CreateNineImagePainter(kImages[orientation][state])
const gfx::ImageSkia* middle = middle_images_[orientation][state]; ->Paint(canvas, view->GetLocalBounds());
const gfx::ImageSkia* trailing = trailing_images_[orientation][state];
gfx::Rect bounds(view->GetLocalBounds());
gfx::Point leading_location, trailing_location;
gfx::Rect middle_bounds;
if (orientation == kImageHorizontal) {
leading_location = gfx::Point(0, 0);
trailing_location = gfx::Point(bounds.width() - trailing->width(), 0);
middle_bounds = gfx::Rect(
leading->width(),
0,
bounds.width() - (leading->width() + trailing->width()),
bounds.height());
} else {
leading_location = gfx::Point(0, 0);
trailing_location = gfx::Point(0, bounds.height() - trailing->height());
middle_bounds = gfx::Rect(
0,
leading->height(),
bounds.width(),
bounds.height() - (leading->height() + trailing->height()));
}
canvas->DrawImageInt(*leading,
leading_location.x(),
leading_location.y());
canvas->DrawImageInt(*trailing,
trailing_location.x(),
trailing_location.y());
canvas->TileImageInt(*middle,
middle_bounds.x(),
middle_bounds.y(),
middle_bounds.width(),
middle_bounds.height());
} }
SkColor color_; SkColor color_;
// Reference to the TrayBackgroundView for which this is a background. // Reference to the TrayBackgroundView for which this is a background.
TrayBackgroundView* tray_background_view_; TrayBackgroundView* tray_background_view_;
// References to the images used as backgrounds, they are owned by the
// resource bundle class.
const gfx::ImageSkia* leading_images_[kNumOrientations][kNumStates];
const gfx::ImageSkia* middle_images_[kNumOrientations][kNumStates];
const gfx::ImageSkia* trailing_images_[kNumOrientations][kNumStates];
DISALLOW_COPY_AND_ASSIGN(TrayBackground); DISALLOW_COPY_AND_ASSIGN(TrayBackground);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment