1f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 2f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// found in the LICENSE file. 4f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 5f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#ifndef CHROME_BROWSER_UI_APP_LIST_APP_LIST_POSITIONER_H_ 6f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#define CHROME_BROWSER_UI_APP_LIST_APP_LIST_POSITIONER_H_ 7f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 8f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ui/gfx/display.h" 9f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ui/gfx/size.h" 10f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 11f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace gfx { 12f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class Point; 13f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class Rect; 14f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 15f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 16f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Helps anchor the App List, onto the shelf (taskbar, dock or similar) or to 17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// the corner of a display. This class does not impose any particular policy for 18f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// when and how to anchor the window. The platform-specific code that uses this 19f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// class is free to decide, for example, when the window should be anchored to 20f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// the cursor versus the corner of the shelf. This class just performs the 21f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// calculations necessary to position the App List correctly. 22f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class AppListPositioner { 23f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) public: 24f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Represents one of the four edges of the screen. 25f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) enum ScreenEdge { 26f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SCREEN_EDGE_UNKNOWN, 27f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SCREEN_EDGE_LEFT, 28f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SCREEN_EDGE_RIGHT, 29f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SCREEN_EDGE_TOP, 30f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SCREEN_EDGE_BOTTOM 31f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) }; 32f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 33f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Represents one of the four corners of the screen. 34f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) enum ScreenCorner { 35f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SCREEN_CORNER_TOP_LEFT, 36f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SCREEN_CORNER_TOP_RIGHT, 37f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SCREEN_CORNER_BOTTOM_LEFT, 38f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SCREEN_CORNER_BOTTOM_RIGHT 39f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) }; 40f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 41f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // The |display| pointer is borrowed, and must outlive this object's lifetime. 42f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // |window_size| is the size of the App List. 43f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // |min_distance_from_edge| is the minimum distance, in pixels, to position 44f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // the app list from the shelf or edge of screen. 45f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) AppListPositioner(const gfx::Display& display, 46f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const gfx::Size& window_size, 47f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) int min_distance_from_edge); 48f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 49f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Subtracts a rectangle from the display's work area. This can be used to 50f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // ensure that the app list does not overlap the shelf, even in situations 51f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // where the shelf is considered part of the work area. 52f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void WorkAreaSubtract(const gfx::Rect& rect); 53f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 54f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Shrinks the display's work area by the given amount on each side. 55f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void WorkAreaInset(int left, int top, int right, int bottom); 56f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 57f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Finds the position for a window to anchor it to a corner of the screen. 58f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // |corner| specifies which corner to anchor the window to. Returns the 59f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // intended coordinates for the center of the window. This should only be used 60f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // when there is no shelf on the display, because if there is, the returned 61f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // anchor point will potentially position the window under it. 62f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Point GetAnchorPointForScreenCorner(ScreenCorner corner) const; 63f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Finds the position for a window to anchor it to the center of the screen. 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Returns the intended coordinates for the center of the window. 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Point GetAnchorPointForScreenCenter() const; 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 68f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Finds the position for a window to anchor it to the corner of the shelf. 69f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // The window will be aligned to the left of the work area for horizontal 70f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // shelves, or to the top for vertical shelves. |shelf_edge| specifies the 71f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // location of the shelf. |shelf_edge| must not be SCREEN_EDGE_UNKNOWN. 72f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Returns the intended coordinates for the center of the window. 73f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Point GetAnchorPointForShelfCorner(ScreenEdge shelf_edge) const; 74f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 75a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Finds the position for a window to anchor it to the center of the shelf. 76a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // |shelf_edge| specifies the location of the shelf. It must not be 77a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // SCREEN_EDGE_UNKNOWN. Returns the intended coordinates for the center of the 78a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // window. 79a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) gfx::Point GetAnchorPointForShelfCenter(ScreenEdge shelf_edge) const; 80a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 81f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Finds the position for a window to anchor it to the shelf at a point 82f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // closest to the user's mouse cursor. |shelf_edge| specifies the location of 83f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // the shelf; |cursor| specifies the location of the user's mouse cursor. 84f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // |shelf_edge| must not be SCREEN_EDGE_UNKNOWN. Returns the intended 85f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // coordinates for the center of the window. 86f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Point GetAnchorPointForShelfCursor(ScreenEdge shelf_edge, 87f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const gfx::Point& cursor) const; 88f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 89f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Determines which edge of the screen the shelf is attached to. Returns 90f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // SCREEN_EDGE_UNKNOWN if the shelf is unavailable, hidden, or not on the 91f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // current screen. 92f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ScreenEdge GetShelfEdge(const gfx::Rect& shelf_rect) const; 93f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 94f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Gets the lateral distance of the mouse cursor from the edge of the shelf. 95f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // For horizontal shelves, this is the vertical distance; for vertical 96f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // shelves, this is the horizontal distance. If the cursor is inside the 97f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // shelf, returns 0. 98f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) int GetCursorDistanceFromShelf(ScreenEdge shelf_edge, 99f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const gfx::Point& cursor) const; 100f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 101f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) private: 102f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Ensures that an anchor point will result in a window that is fully within 103f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // the work area. Returns the updated anchor point. 104f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Point ClampAnchorPoint(gfx::Point anchor) const; 105f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 106f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Display display_; 107f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 108f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Size of the App List. 109f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::Size window_size_; 110f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 111f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // The minimum distance, in pixels, to position the app list from the shelf 112f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // or edge of screen. 113f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) int min_distance_from_edge_; 114f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}; 115f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 116f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_POSITIONER_H_ 117