This source file includes following definitions.
- GetTaskbarRect
- window_icon_updated_
- FindAnchorPoint
- Show
- Hide
- MoveNearCursor
- IsVisible
- Prerender
- ReactivateOnNextFocusLoss
- GetWindow
- SetProfile
#include "chrome/browser/ui/views/app_list/win/app_list_win.h"
#include "base/command_line.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"
namespace {
static const wchar_t kTrayClassName[] = L"Shell_TrayWnd";
static const int kSnapDistance = 50;
static const int kMinDistanceFromEdge = 3;
bool GetTaskbarRect(gfx::Rect* rect) {
HWND taskbar_hwnd = FindWindow(kTrayClassName, NULL);
if (!taskbar_hwnd)
return false;
RECT win_rect;
if (!GetWindowRect(taskbar_hwnd, &win_rect))
return false;
*rect = gfx::Rect(win_rect);
return true;
}
}
AppListWin::AppListWin(app_list::AppListView* view,
const base::Closure& on_should_dismiss)
: view_(view),
activation_tracker_(view, on_should_dismiss),
window_icon_updated_(false) {}
AppListWin::~AppListWin() {}
gfx::Point AppListWin::FindAnchorPoint(const gfx::Size& view_size,
const gfx::Display& display,
const gfx::Point& cursor,
const gfx::Rect& taskbar_rect) {
AppListPositioner positioner(display, view_size, kMinDistanceFromEdge);
positioner.WorkAreaSubtract(taskbar_rect);
if (app_list::switches::IsExperimentalAppListPositionEnabled())
return positioner.GetAnchorPointForScreenCenter();
AppListPositioner::ScreenEdge edge = positioner.GetShelfEdge(taskbar_rect);
gfx::Point anchor;
if (edge == AppListPositioner::SCREEN_EDGE_UNKNOWN) {
return positioner.GetAnchorPointForScreenCorner(
AppListPositioner::SCREEN_CORNER_BOTTOM_LEFT);
}
if (positioner.GetCursorDistanceFromShelf(edge, cursor) > kSnapDistance)
return positioner.GetAnchorPointForShelfCorner(edge);
return positioner.GetAnchorPointForShelfCursor(edge, cursor);
}
void AppListWin::Show() {
view_->GetWidget()->Show();
if (!window_icon_updated_) {
view_->GetWidget()->GetTopLevelWidget()->UpdateWindowIcon();
window_icon_updated_ = true;
}
view_->GetWidget()->Activate();
}
void AppListWin::Hide() {
view_->GetWidget()->Hide();
activation_tracker_.OnViewHidden();
}
void AppListWin::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);
gfx::Rect taskbar_rect;
GetTaskbarRect(&taskbar_rect);
view_->SetAnchorPoint(FindAnchorPoint(view_->GetPreferredSize(), display,
cursor, taskbar_rect));
}
bool AppListWin::IsVisible() {
return view_->GetWidget()->IsVisible();
}
void AppListWin::Prerender() {
view_->Prerender();
}
void AppListWin::ReactivateOnNextFocusLoss() {
activation_tracker_.ReactivateOnNextFocusLoss();
}
gfx::NativeWindow AppListWin::GetWindow() {
return view_->GetWidget()->GetNativeWindow();
}
void AppListWin::SetProfile(Profile* profile) {
view_->SetProfileByPath(profile->GetPath());
}