Hide Skip Ad tooltip if not visible in Picture-in-Picture window

Bug: 926121, 926679
Change-Id: Ia562854262a4245197577274b3f3fed67bf65853
Reviewed-on: https://chromium-review.googlesource.com/c/1443011
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Reviewed-by: Mounir Lamouri <mlamouri@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#627577}(cherry picked from commit 7ffc24cbc9a6a4b5e4afbe023f678f17c51b5449)
Reviewed-on: https://chromium-review.googlesource.com/c/1448240
Reviewed-by: François Beaufort <beaufort.francois@gmail.com>
Cr-Commit-Position: refs/branch-heads/3683@{#106}
Cr-Branched-From: e51029943e0a38dd794b73caaf6373d5496ae783-refs/heads/master@{#625896}
diff --git a/chrome/browser/ui/views/overlay/overlay_window_views.cc b/chrome/browser/ui/views/overlay/overlay_window_views.cc
index 4cf13f6..1335673 100644
--- a/chrome/browser/ui/views/overlay/overlay_window_views.cc
+++ b/chrome/browser/ui/views/overlay/overlay_window_views.cc
@@ -443,10 +443,12 @@
   GetControlsScrimLayer()->SetVisible(is_visible);
   GetControlsParentLayer()->SetVisible(is_visible);
   GetBackToTabControlsLayer()->SetVisible(is_visible);
-  GetSkipAdControlsLayer()->SetVisible(is_visible && show_skip_ad_button_);
-  skip_ad_controls_view_->SetEnabled(is_visible && show_skip_ad_button_);
   GetCloseControlsLayer()->SetVisible(is_visible);
 
+  // We need to do more than usual visibility change because otherwise control
+  // is accessible via accessibility tools.
+  skip_ad_controls_view_->ToggleVisibility(is_visible && show_skip_ad_button_);
+
 #if defined(OS_CHROMEOS)
   GetResizeHandleLayer()->SetVisible(is_visible);
 #endif
diff --git a/chrome/browser/ui/views/overlay/skip_ad_label_button.cc b/chrome/browser/ui/views/overlay/skip_ad_label_button.cc
index 2d15883..bd1d995 100644
--- a/chrome/browser/ui/views/overlay/skip_ad_label_button.cc
+++ b/chrome/browser/ui/views/overlay/skip_ad_label_button.cc
@@ -47,4 +47,11 @@
       size.height() - kSkipAdButtonHeight - kSkipAdButtonMarginBottom));
 }
 
+void SkipAdLabelButton::ToggleVisibility(bool is_visible) {
+  layer()->SetVisible(is_visible);
+  SetEnabled(is_visible);
+  SetSize(is_visible ? gfx::Size(kSkipAdButtonWidth, kSkipAdButtonHeight)
+                     : gfx::Size());
+}
+
 }  // namespace views
diff --git a/chrome/browser/ui/views/overlay/skip_ad_label_button.h b/chrome/browser/ui/views/overlay/skip_ad_label_button.h
index a3d545d..1b17b9a 100644
--- a/chrome/browser/ui/views/overlay/skip_ad_label_button.h
+++ b/chrome/browser/ui/views/overlay/skip_ad_label_button.h
@@ -19,6 +19,9 @@
   // Sets the position of itself with an offset from the given window size.
   void SetPosition(const gfx::Size& size);
 
+  // Toggle visibility.
+  void ToggleVisibility(bool is_visible);
+
  private:
   DISALLOW_COPY_AND_ASSIGN(SkipAdLabelButton);
 };