Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: ash/tooltips/tooltip_controller.cc

Issue 11030017: Add context to gfx::Screen calls in support of simultaneous desktop+ash (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tidy Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 =
72 gfx::Screen::GetDisplayNearestPoint(gfx::Point(x, y)).bounds(); 72 gfx::Screen::GetDisplayNearestPoint(
73 ash::Shell::GetPrimaryRootWindow(),
74 gfx::Point(x, y)).bounds();
73 return (display_bounds.width() + 1) / 2; 75 return (display_bounds.width() + 1) / 2;
74 } 76 }
75 77
76 // Creates a widget of type TYPE_TOOLTIP 78 // Creates a widget of type TYPE_TOOLTIP
77 views::Widget* CreateTooltip() { 79 views::Widget* CreateTooltip() {
78 views::Widget* widget = new views::Widget; 80 views::Widget* widget = new views::Widget;
79 views::Widget::InitParams params; 81 views::Widget::InitParams params;
80 // For aura, since we set the type to TOOLTIP_TYPE, the widget will get 82 // For aura, since we set the type to TOOLTIP_TYPE, the widget will get
81 // auto-parented to the MenuAndTooltipsContainer. 83 // auto-parented to the MenuAndTooltipsContainer.
82 params.type = views::Widget::InitParams::TYPE_TOOLTIP; 84 params.type = views::Widget::InitParams::TYPE_TOOLTIP;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 // Adjusts the bounds given by the arguments to fit inside the desktop 160 // Adjusts the bounds given by the arguments to fit inside the desktop
159 // and applies the adjusted bounds to the label_. 161 // and applies the adjusted bounds to the label_.
160 void SetTooltipBounds(gfx::Point mouse_pos, 162 void SetTooltipBounds(gfx::Point mouse_pos,
161 int tooltip_width, 163 int tooltip_width,
162 int tooltip_height) { 164 int tooltip_height) {
163 gfx::Rect tooltip_rect(mouse_pos.x(), mouse_pos.y(), tooltip_width, 165 gfx::Rect tooltip_rect(mouse_pos.x(), mouse_pos.y(), tooltip_width,
164 tooltip_height); 166 tooltip_height);
165 167
166 tooltip_rect.Offset(kCursorOffsetX, kCursorOffsetY); 168 tooltip_rect.Offset(kCursorOffsetX, kCursorOffsetY);
167 gfx::Rect display_bounds = 169 gfx::Rect display_bounds =
168 gfx::Screen::GetDisplayNearestPoint(tooltip_rect.origin()).bounds(); 170 gfx::Screen::GetDisplayNearestPoint(
171 ash::Shell::GetPrimaryRootWindow(),
172 tooltip_rect.origin()).bounds();
169 173
170 // If tooltip is out of bounds on the x axis, we simply shift it 174 // If tooltip is out of bounds on the x axis, we simply shift it
171 // horizontally by the offset. 175 // horizontally by the offset.
172 if (tooltip_rect.right() > display_bounds.right()) { 176 if (tooltip_rect.right() > display_bounds.right()) {
173 int h_offset = tooltip_rect.right() - display_bounds.right(); 177 int h_offset = tooltip_rect.right() - display_bounds.right();
174 tooltip_rect.Offset(-h_offset, 0); 178 tooltip_rect.Offset(-h_offset, 0);
175 } 179 }
176 180
177 // If tooltip is out of bounds on the y axis, we flip it to appear above the 181 // If tooltip is out of bounds on the y axis, we flip it to appear above the
178 // mouse cursor instead of below. 182 // mouse cursor instead of below.
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 } 474 }
471 475
472 TooltipController::Tooltip* TooltipController::GetTooltip() { 476 TooltipController::Tooltip* TooltipController::GetTooltip() {
473 if (!tooltip_.get()) 477 if (!tooltip_.get())
474 tooltip_.reset(new Tooltip); 478 tooltip_.reset(new Tooltip);
475 return tooltip_.get(); 479 return tooltip_.get();
476 } 480 }
477 481
478 } // namespace internal 482 } // namespace internal
479 } // namespace ash 483 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698