15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2011 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/tooltip_manager.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
74e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ui/gfx/rect.h"
84e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ui/gfx/screen.h"
958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "ui/gfx/text_elider.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)namespace views {
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)const size_t kMaxTooltipLength = 1024;
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// static
161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)const char TooltipManager::kGroupingPropertyKey[] = "GroupingPropertyKey";
171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// static
194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)int TooltipManager::GetMaxWidth(int x, int y, gfx::NativeView context) {
204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  return GetMaxWidth(gfx::Screen::GetScreenFor(context)->GetDisplayNearestPoint(
214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                         gfx::Point(x, y)));
224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)int TooltipManager::GetMaxWidth(const gfx::Display& display) {
264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  return (display.bounds().width() + 1) / 2;
274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// static
304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void TooltipManager::TrimTooltipText(base::string16* text) {
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Clamp the tooltip length to kMaxTooltipLength so that we don't
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // accidentally DOS the user with a mega tooltip.
335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  *text = gfx::TruncateString(*text, kMaxTooltipLength, gfx::WORD_BREAK);
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace views
37