This source file includes following definitions.
- on_should_dismiss_
- FindAnchorPoint
- Show
- Hide
- MoveNearCursor
- IsVisible
- Prerender
- ReactivateOnNextFocusLoss
- GetWindow
- SetProfile
- OnActivationChanged
#include "chrome/browser/ui/views/app_list/linux/app_list_linux.h"
#include "base/command_line.h"
#include "base/location.h"
#include "base/single_thread_task_runner.h"
#include "base/thread_task_runner_handle.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/app_list_positioner.h"
#include "ui/app_list/app_list_switches.h"
#include "ui/app_list/views/app_list_view.h"
#include "ui/gfx/screen.h"
#include "ui/views/widget/widget.h"
AppListLinux::AppListLinux(app_list::AppListView* view,
const base::Closure& on_should_dismiss)
: view_(view),
window_icon_updated_(false),
on_should_dismiss_(on_should_dismiss) {
view_->AddObserver(this);
}
AppListLinux::~AppListLinux() {
view_->RemoveObserver(this);
}
gfx::Point AppListLinux::FindAnchorPoint(const gfx::Size& view_size,
const gfx::Display& display,
const gfx::Point& cursor,
AppListPositioner::ScreenEdge edge) {
AppListPositioner positioner(display, view_size, 0);
if (app_list::switches::IsExperimentalAppListPositionEnabled())
return positioner.GetAnchorPointForScreenCenter();
gfx::Point anchor;
if (edge == AppListPositioner::SCREEN_EDGE_UNKNOWN) {
return positioner.GetAnchorPointForScreenCorner(
AppListPositioner::SCREEN_CORNER_TOP_LEFT);
}
int snap_distance = edge == AppListPositioner::SCREEN_EDGE_BOTTOM ||
edge == AppListPositioner::SCREEN_EDGE_TOP
? view_size.height()
: view_size.width();
if (positioner.GetCursorDistanceFromShelf(edge, cursor) > snap_distance)
return positioner.GetAnchorPointForShelfCorner(edge);
return positioner.GetAnchorPointForShelfCursor(edge, cursor);
}
void AppListLinux::Show() {
view_->GetWidget()->Show();
if (!window_icon_updated_) {
view_->GetWidget()->GetTopLevelWidget()->UpdateWindowIcon();
window_icon_updated_ = true;
}
view_->GetWidget()->Activate();
}
void AppListLinux::Hide() {
view_->GetWidget()->Hide();
}
void AppListLinux::MoveNearCursor() {
gfx::Point cursor = gfx::Screen::GetNativeScreen()->GetCursorScreenPoint();
gfx::Screen* screen =
gfx::Screen::GetScreenFor(view_->GetWidget()->GetNativeView());
gfx::Display display = screen->GetDisplayNearestPoint(cursor);
view_->SetBubbleArrow(views::BubbleBorder::FLOAT);
AppListPositioner::ScreenEdge edge = AppListPositioner::SCREEN_EDGE_LEFT;
view_->SetAnchorPoint(FindAnchorPoint(view_->GetPreferredSize(), display,
cursor, edge));
}
bool AppListLinux::IsVisible() {
return view_->GetWidget()->IsVisible();
}
void AppListLinux::Prerender() {
view_->Prerender();
}
void AppListLinux::ReactivateOnNextFocusLoss() {
}
gfx::NativeWindow AppListLinux::GetWindow() {
return view_->GetWidget()->GetNativeWindow();
}
void AppListLinux::SetProfile(Profile* profile) {
view_->SetProfileByPath(profile->GetPath());
}
void AppListLinux::OnActivationChanged(
views::Widget* , bool active) {
if (active)
return;
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, on_should_dismiss_);
}