Commit eeed0e85 authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

system: System bubble placed correctly when leaving tablet mode.

This does not fix for non-unified system tray.

Test: manual
Bug: 855216, 812536
Change-Id: I1705d248e784ad8f021b4d13d76956187f1d94a1
Reviewed-on: https://chromium-review.googlesource.com/1110946Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarTetsui Ohkubo <tetsui@chromium.org>
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569851}
parent 39b4aa89
......@@ -21,6 +21,7 @@
#include "ash/system/tray/system_tray.h"
#include "ash/system/unified/unified_system_tray.h"
#include "ash/system/virtual_keyboard/virtual_keyboard_tray.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "base/command_line.h"
#include "base/i18n/time_formatting.h"
#include "ui/base/ui_base_features.h"
......@@ -188,8 +189,11 @@ void StatusAreaWidget::SetSystemTrayVisibility(bool visible) {
}
TrayBackgroundView* StatusAreaWidget::GetSystemTrayAnchor() const {
if (overview_button_tray_->visible())
if (Shell::Get()
->tablet_mode_controller()
->IsTabletModeWindowManagerEnabled()) {
return overview_button_tray_.get();
}
if (unified_system_tray_)
return unified_system_tray_.get();
return system_tray_.get();
......
......@@ -5,13 +5,16 @@
#include "ash/system/unified/unified_system_tray_bubble.h"
#include "ash/public/cpp/app_list/app_list_features.h"
#include "ash/shell.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_event_filter.h"
#include "ash/system/unified/unified_system_tray.h"
#include "ash/system/unified/unified_system_tray_controller.h"
#include "ash/system/unified/unified_system_tray_view.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "base/metrics/histogram_macros.h"
#include "ui/aura/window.h"
namespace ash {
......@@ -68,9 +71,12 @@ UnifiedSystemTrayBubble::UnifiedSystemTrayBubble(UnifiedSystemTray* tray,
}
tray->tray_event_filter()->AddBubble(this);
Shell::Get()->tablet_mode_controller()->AddObserver(this);
}
UnifiedSystemTrayBubble::~UnifiedSystemTrayBubble() {
if (Shell::Get()->tablet_mode_controller())
Shell::Get()->tablet_mode_controller()->RemoveObserver(this);
tray_->tray_event_filter()->RemoveBubble(this);
if (bubble_widget_) {
bubble_widget_->RemoveObserver(this);
......@@ -144,4 +150,31 @@ void UnifiedSystemTrayBubble::RecordTimeToClick() {
time_shown_by_click_.reset();
}
void UnifiedSystemTrayBubble::OnTabletModeStarted() {
UpdateBubbleBounds();
}
void UnifiedSystemTrayBubble::OnTabletModeEnded() {
UpdateBubbleBounds();
}
void UnifiedSystemTrayBubble::UpdateBubbleBounds() {
// If the bubble is open while switching to and from tablet mode, change the
// bubble anchor if needed. The new anchor view may also have a translation
// applied to it so shift the bubble bounds so that it appears in the correct
// location.
bubble_view_->ChangeAnchorView(
tray_->shelf()->GetSystemTrayAnchor()->GetBubbleAnchor());
gfx::Rect bounds =
bubble_view_->GetWidget()->GetNativeWindow()->GetBoundsInScreen();
const gfx::Vector2dF translation = tray_->shelf()
->GetSystemTrayAnchor()
->layer()
->transform()
.To2dTranslation();
bounds.set_x(bounds.x() - translation.x());
bounds.set_y(bounds.y() - translation.y());
bubble_view_->GetWidget()->GetNativeWindow()->SetBounds(bounds);
}
} // namespace ash
......@@ -9,6 +9,7 @@
#include "ash/system/tray/time_to_click_recorder.h"
#include "ash/system/tray/tray_bubble_base.h"
#include "ash/wm/tablet_mode/tablet_mode_observer.h"
#include "base/macros.h"
#include "base/optional.h"
#include "base/time/time.h"
......@@ -30,7 +31,8 @@ class UnifiedSystemTrayView;
// case, this class calls UnifiedSystemTray::CloseBubble() to delete itself.
class UnifiedSystemTrayBubble : public TrayBubbleBase,
public views::WidgetObserver,
public TimeToClickRecorder::Delegate {
public TimeToClickRecorder::Delegate,
public TabletModeObserver {
public:
explicit UnifiedSystemTrayBubble(UnifiedSystemTray* tray, bool show_by_click);
~UnifiedSystemTrayBubble() override;
......@@ -58,9 +60,15 @@ class UnifiedSystemTrayBubble : public TrayBubbleBase,
// TimeToClickRecorder::Delegate:
void RecordTimeToClick() override;
// TabletModeObserver:
void OnTabletModeStarted() override;
void OnTabletModeEnded() override;
private:
friend class UnifiedSystemTrayTestApi;
void UpdateBubbleBounds();
// Controller of UnifiedSystemTrayView. As the view is owned by views
// hierarchy, we have to own the controller here.
std::unique_ptr<UnifiedSystemTrayController> controller_;
......
......@@ -312,6 +312,10 @@ void TrayBubbleView::ResetDelegate() {
delegate_ = nullptr;
}
void TrayBubbleView::ChangeAnchorView(views::View* anchor_view) {
BubbleDialogDelegateView::SetAnchorView(anchor_view);
}
int TrayBubbleView::GetDialogButtons() const {
return ui::DIALOG_BUTTON_NONE;
}
......
......@@ -130,6 +130,9 @@ class VIEWS_EXPORT TrayBubbleView : public BubbleDialogDelegateView,
// ResetDelegate.
void ResetDelegate();
// Anchors the bubble to |anchor_view|.
void ChangeAnchorView(views::View* anchor_view);
Delegate* delegate() { return delegate_; }
void set_gesture_dragging(bool dragging) { is_gesture_dragging_ = dragging; }
......
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