Commit 94d82d59 authored by Jennifer Apacible's avatar Jennifer Apacible Committed by Commit Bot

[OverlayWindowViews] Update naming and styling.

Change-Id: I138c4e57f47af2750dc66cea9981a455e5d5b60f
Reviewed-on: https://chromium-review.googlesource.com/1246786
Commit-Queue: apacible <apacible@chromium.org>
Reviewed-by: default avatarCJ DiMeglio <lethalantidote@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594849}
parent ed9bc9f3
...@@ -360,20 +360,20 @@ void OverlayWindowViews::UpdateButtonSize() { ...@@ -360,20 +360,20 @@ void OverlayWindowViews::UpdateButtonSize() {
} }
void OverlayWindowViews::UpdateCustomControlsSize( void OverlayWindowViews::UpdateCustomControlsSize(
views::ControlImageButton* control) { views::ControlImageButton* control_button) {
if (!control) if (!control_button)
return; return;
UpdateButtonSize(); UpdateButtonSize();
control->SetSize(button_size_); control_button->SetSize(button_size_);
// TODO(sawtelle): Download the images and add them to the controls. // TODO(sawtelle): Download the images and add them to the controls.
// https://crbug.com/864271. // https://crbug.com/864271.
if (control == first_custom_controls_view_.get()) { if (control_button == first_custom_controls_view_.get()) {
first_custom_controls_view_->SetImage( first_custom_controls_view_->SetImage(
views::Button::STATE_NORMAL, views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(kPlayArrowIcon, button_size_.width() / 2, gfx::CreateVectorIcon(kPlayArrowIcon, button_size_.width() / 2,
kControlIconColor)); kControlIconColor));
} }
if (control == second_custom_controls_view_.get()) { if (control_button == second_custom_controls_view_.get()) {
second_custom_controls_view_->SetImage( second_custom_controls_view_->SetImage(
views::Button::STATE_NORMAL, views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(kPauseIcon, button_size_.width() / 2, gfx::CreateVectorIcon(kPauseIcon, button_size_.width() / 2,
...@@ -381,8 +381,8 @@ void OverlayWindowViews::UpdateCustomControlsSize( ...@@ -381,8 +381,8 @@ void OverlayWindowViews::UpdateCustomControlsSize(
} }
const gfx::ImageSkia control_background = gfx::CreateVectorIcon( const gfx::ImageSkia control_background = gfx::CreateVectorIcon(
kPictureInPictureControlBackgroundIcon, button_size_.width(), kBgColor); kPictureInPictureControlBackgroundIcon, button_size_.width(), kBgColor);
control->SetBackgroundImage(kBgColor, &control_background, control_button->SetBackgroundImage(kBgColor, &control_background,
&control_background); &control_background);
} }
void OverlayWindowViews::UpdatePlayPauseControlsSize() { void OverlayWindowViews::UpdatePlayPauseControlsSize() {
...@@ -402,32 +402,30 @@ void OverlayWindowViews::UpdatePlayPauseControlsSize() { ...@@ -402,32 +402,30 @@ void OverlayWindowViews::UpdatePlayPauseControlsSize() {
kBgColor, &play_pause_background, &play_pause_background); kBgColor, &play_pause_background, &play_pause_background);
} }
void OverlayWindowViews::SetUpCustomControl( void OverlayWindowViews::CreateCustomControl(
std::unique_ptr<views::ControlImageButton>& control, std::unique_ptr<views::ControlImageButton>& control_button,
const blink::PictureInPictureControlInfo& web_control, const blink::PictureInPictureControlInfo& info,
ControlPosition position) { ControlPosition position) {
if (!control) { control_button = std::make_unique<views::ControlImageButton>(this);
control = std::make_unique<views::ControlImageButton>(this); controls_parent_view_->AddChildView(control_button.get());
controls_parent_view_->AddChildView(control.get()); control_button->set_id(info.id);
control->set_owned_by_client(); control_button->set_owned_by_client();
control->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
views::ImageButton::ALIGN_MIDDLE); // Sizing / positioning.
} control_button->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
views::ImageButton::ALIGN_MIDDLE);
// Sizing/positioning. UpdateCustomControlsSize(control_button.get());
UpdateCustomControlsSize(control.get());
control->set_id(web_control.id);
UpdateControlsBounds(); UpdateControlsBounds();
// Accessibility. // Accessibility.
base::string16 custom_button_label = base::UTF8ToUTF16(web_control.label); base::string16 custom_button_label = base::UTF8ToUTF16(info.label);
control->SetAccessibleName(custom_button_label); control_button->SetAccessibleName(custom_button_label);
control->SetTooltipText(custom_button_label); control_button->SetTooltipText(custom_button_label);
control->SetInstallFocusRingOnFocus(true); control_button->SetInstallFocusRingOnFocus(true);
control->SetFocusForPlatform(); control_button->SetFocusForPlatform();
} }
bool OverlayWindowViews::OnlyOneCustomControlAdded() { bool OverlayWindowViews::HasOnlyOneCustomControl() {
return first_custom_controls_view_ && !second_custom_controls_view_; return first_custom_controls_view_ && !second_custom_controls_view_;
} }
...@@ -448,7 +446,7 @@ void OverlayWindowViews::UpdateControlsPositions() { ...@@ -448,7 +446,7 @@ void OverlayWindowViews::UpdateControlsPositions() {
// | [1] [P] | // | [1] [P] |
// | | // | |
// |__________________________| // |__________________________|
if (OnlyOneCustomControlAdded()) { if (HasOnlyOneCustomControl()) {
play_pause_controls_view_->SetBoundsRect( play_pause_controls_view_->SetBoundsRect(
CalculateControlsBounds(mid_window_x, button_size_)); CalculateControlsBounds(mid_window_x, button_size_));
first_custom_controls_view_->SetBoundsRect(CalculateControlsBounds( first_custom_controls_view_->SetBoundsRect(CalculateControlsBounds(
...@@ -556,12 +554,16 @@ void OverlayWindowViews::SetAlwaysHidePlayPauseButton(bool is_visible) { ...@@ -556,12 +554,16 @@ void OverlayWindowViews::SetAlwaysHidePlayPauseButton(bool is_visible) {
void OverlayWindowViews::SetPictureInPictureCustomControls( void OverlayWindowViews::SetPictureInPictureCustomControls(
const std::vector<blink::PictureInPictureControlInfo>& controls) { const std::vector<blink::PictureInPictureControlInfo>& controls) {
// Clear any existing controls.
first_custom_controls_view_.reset();
second_custom_controls_view_.reset();
if (controls.size() > 0) if (controls.size() > 0)
SetUpCustomControl(first_custom_controls_view_, controls[0], CreateCustomControl(first_custom_controls_view_, controls[0],
ControlPosition::kLeft); ControlPosition::kLeft);
if (controls.size() > 1) if (controls.size() > 1)
SetUpCustomControl(second_custom_controls_view_, controls[1], CreateCustomControl(second_custom_controls_view_, controls[1],
ControlPosition::kRight); ControlPosition::kRight);
} }
ui::Layer* OverlayWindowViews::GetWindowBackgroundLayer() { ui::Layer* OverlayWindowViews::GetWindowBackgroundLayer() {
......
...@@ -99,15 +99,16 @@ class OverlayWindowViews : public content::OverlayWindow, ...@@ -99,15 +99,16 @@ class OverlayWindowViews : public content::OverlayWindow,
void UpdateButtonSize(); void UpdateButtonSize();
// Update the size of each controls view as the size of the window changes. // Update the size of each controls view as the size of the window changes.
void UpdateCustomControlsSize(views::ControlImageButton*); void UpdateCustomControlsSize(views::ControlImageButton* control_button);
void UpdatePlayPauseControlsSize(); void UpdatePlayPauseControlsSize();
void SetUpCustomControl(std::unique_ptr<views::ControlImageButton>&, void CreateCustomControl(
const blink::PictureInPictureControlInfo&, std::unique_ptr<views::ControlImageButton>& control_button,
ControlPosition); const blink::PictureInPictureControlInfo& info,
ControlPosition position);
// Returns whether there is exactly one custom control on the window. // Returns whether there is exactly one custom control on the window.
bool OnlyOneCustomControlAdded(); bool HasOnlyOneCustomControl();
// Calculate and set the bounds of the controls. // Calculate and set the bounds of the controls.
gfx::Rect CalculateControlsBounds(int x, const gfx::Size& size); gfx::Rect CalculateControlsBounds(int x, const gfx::Size& size);
......
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