OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/tooltips/tooltip_controller.h" | 5 #include "ash/tooltips/tooltip_controller.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 gfx::Font GetDefaultFont() { | 61 gfx::Font GetDefaultFont() { |
62 // TODO(varunjain): implementation duplicated in tooltip_manager_aura. Figure | 62 // TODO(varunjain): implementation duplicated in tooltip_manager_aura. Figure |
63 // out a way to merge. | 63 // out a way to merge. |
64 return ui::ResourceBundle::GetSharedInstance().GetFont( | 64 return ui::ResourceBundle::GetSharedInstance().GetFont( |
65 ui::ResourceBundle::BaseFont); | 65 ui::ResourceBundle::BaseFont); |
66 } | 66 } |
67 | 67 |
68 int GetMaxWidth(int x, int y) { | 68 int GetMaxWidth(int x, int y) { |
69 // TODO(varunjain): implementation duplicated in tooltip_manager_aura. Figure | 69 // TODO(varunjain): implementation duplicated in tooltip_manager_aura. Figure |
70 // out a way to merge. | 70 // out a way to merge. |
71 gfx::Rect display_bounds = | 71 gfx::Rect display_bounds = ash::Shell::GetScreen()->GetDisplayNearestPoint( |
72 gfx::Screen::GetDisplayNearestPoint(gfx::Point(x, y)).bounds(); | 72 gfx::Point(x, y)).bounds(); |
73 return (display_bounds.width() + 1) / 2; | 73 return (display_bounds.width() + 1) / 2; |
74 } | 74 } |
75 | 75 |
76 // Creates a widget of type TYPE_TOOLTIP | 76 // Creates a widget of type TYPE_TOOLTIP |
77 views::Widget* CreateTooltip() { | 77 views::Widget* CreateTooltip() { |
78 views::Widget* widget = new views::Widget; | 78 views::Widget* widget = new views::Widget; |
79 views::Widget::InitParams params; | 79 views::Widget::InitParams params; |
80 // For aura, since we set the type to TOOLTIP_TYPE, the widget will get | 80 // For aura, since we set the type to TOOLTIP_TYPE, the widget will get |
81 // auto-parented to the MenuAndTooltipsContainer. | 81 // auto-parented to the MenuAndTooltipsContainer. |
82 params.type = views::Widget::InitParams::TYPE_TOOLTIP; | 82 params.type = views::Widget::InitParams::TYPE_TOOLTIP; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 157 |
158 // Adjusts the bounds given by the arguments to fit inside the desktop | 158 // Adjusts the bounds given by the arguments to fit inside the desktop |
159 // and applies the adjusted bounds to the label_. | 159 // and applies the adjusted bounds to the label_. |
160 void SetTooltipBounds(gfx::Point mouse_pos, | 160 void SetTooltipBounds(gfx::Point mouse_pos, |
161 int tooltip_width, | 161 int tooltip_width, |
162 int tooltip_height) { | 162 int tooltip_height) { |
163 gfx::Rect tooltip_rect(mouse_pos.x(), mouse_pos.y(), tooltip_width, | 163 gfx::Rect tooltip_rect(mouse_pos.x(), mouse_pos.y(), tooltip_width, |
164 tooltip_height); | 164 tooltip_height); |
165 | 165 |
166 tooltip_rect.Offset(kCursorOffsetX, kCursorOffsetY); | 166 tooltip_rect.Offset(kCursorOffsetX, kCursorOffsetY); |
167 gfx::Rect display_bounds = | 167 gfx::Rect display_bounds = Shell::GetScreen()->GetDisplayNearestPoint( |
168 gfx::Screen::GetDisplayNearestPoint(tooltip_rect.origin()).bounds(); | 168 tooltip_rect.origin()).bounds(); |
169 | 169 |
170 // If tooltip is out of bounds on the x axis, we simply shift it | 170 // If tooltip is out of bounds on the x axis, we simply shift it |
171 // horizontally by the offset. | 171 // horizontally by the offset. |
172 if (tooltip_rect.right() > display_bounds.right()) { | 172 if (tooltip_rect.right() > display_bounds.right()) { |
173 int h_offset = tooltip_rect.right() - display_bounds.right(); | 173 int h_offset = tooltip_rect.right() - display_bounds.right(); |
174 tooltip_rect.Offset(-h_offset, 0); | 174 tooltip_rect.Offset(-h_offset, 0); |
175 } | 175 } |
176 | 176 |
177 // If tooltip is out of bounds on the y axis, we flip it to appear above the | 177 // If tooltip is out of bounds on the y axis, we flip it to appear above the |
178 // mouse cursor instead of below. | 178 // mouse cursor instead of below. |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 } | 470 } |
471 | 471 |
472 TooltipController::Tooltip* TooltipController::GetTooltip() { | 472 TooltipController::Tooltip* TooltipController::GetTooltip() { |
473 if (!tooltip_.get()) | 473 if (!tooltip_.get()) |
474 tooltip_.reset(new Tooltip); | 474 tooltip_.reset(new Tooltip); |
475 return tooltip_.get(); | 475 return tooltip_.get(); |
476 } | 476 } |
477 | 477 |
478 } // namespace internal | 478 } // namespace internal |
479 } // namespace ash | 479 } // namespace ash |
OLD | NEW |