| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <limits> | 5 #include <limits> |
| 6 | 6 |
| 7 #include "chrome/common/gfx/chrome_font.h" | 7 #include "chrome/common/gfx/chrome_font.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "chrome/common/l10n_util.h" | 10 #include "chrome/common/l10n_util.h" |
| 11 #include "chrome/common/gfx/url_elider.h" | 11 #include "chrome/common/gfx/url_elider.h" |
| 12 #include "chrome/common/win_util.h" | 12 #include "chrome/common/win_util.h" |
| 13 #include "chrome/views/root_view.h" | 13 #include "chrome/views/root_view.h" |
| 14 #include "chrome/views/tooltip_manager.h" | 14 #include "chrome/views/tooltip_manager.h" |
| 15 #include "chrome/views/view.h" | 15 #include "chrome/views/view.h" |
| 16 #include "chrome/views/view_container.h" | 16 #include "chrome/views/view_container.h" |
| 17 | 17 |
| 18 namespace ChromeViews { | 18 namespace ChromeViews { |
| 19 | 19 |
| 20 //static | 20 //static |
| 21 int TooltipManager::tooltip_height_ = 0; | 21 int TooltipManager::tooltip_height_ = 0; |
| 22 | 22 |
| 23 // Default timeout for the tooltip displayed using keyboard. | 23 // Default timeout for the tooltip displayed using keyboard. |
| 24 // Timeout is mentioned in milliseconds. | 24 // Timeout is mentioned in milliseconds. |
| 25 static const int kDefaultTimeout = 4000; | 25 static const int kDefaultTimeout = 4000; |
| 26 | 26 |
| 27 // Maximum number of lines we allow in the tooltip. | 27 // Maximum number of lines we allow in the tooltip. |
| 28 static const int kMaxLines = 6; | 28 static const int kMaxLines = 6; |
| 29 | 29 |
| 30 // Maximum number of characters we allow in a tooltip. |
| 31 static const int kMaxTooltipLength = 1024; |
| 32 |
| 30 // Breaks |text| along line boundaries, placing each line of text into lines. | 33 // Breaks |text| along line boundaries, placing each line of text into lines. |
| 31 static void SplitTooltipString(const std::wstring& text, | 34 static void SplitTooltipString(const std::wstring& text, |
| 32 std::vector<std::wstring>* lines) { | 35 std::vector<std::wstring>* lines) { |
| 33 size_t index = 0; | 36 size_t index = 0; |
| 34 size_t next_index; | 37 size_t next_index; |
| 35 while ((next_index = text.find(TooltipManager::GetLineSeparator(), index)) | 38 while ((next_index = text.find(TooltipManager::GetLineSeparator(), index)) |
| 36 != std::wstring::npos && lines->size() < kMaxLines) { | 39 != std::wstring::npos && lines->size() < kMaxLines) { |
| 37 lines->push_back(text.substr(index, next_index - index)); | 40 lines->push_back(text.substr(index, next_index - index)); |
| 38 index = next_index + TooltipManager::GetLineSeparator().size(); | 41 index = next_index + TooltipManager::GetLineSeparator().size(); |
| 39 } | 42 } |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 | 268 |
| 266 void TooltipManager::TrimTooltipToFit(std::wstring* text, | 269 void TooltipManager::TrimTooltipToFit(std::wstring* text, |
| 267 int* max_width, | 270 int* max_width, |
| 268 int* line_count, | 271 int* line_count, |
| 269 int position_x, | 272 int position_x, |
| 270 int position_y, | 273 int position_y, |
| 271 HWND window) { | 274 HWND window) { |
| 272 *max_width = 0; | 275 *max_width = 0; |
| 273 *line_count = 0; | 276 *line_count = 0; |
| 274 | 277 |
| 278 // Clamp the tooltip length to kMaxTooltipLength so that we don't |
| 279 // accidentally DOS the user with a mega tooltip (since Windows doesn't seem |
| 280 // to do this itself). |
| 281 if (text->length() > kMaxTooltipLength) |
| 282 *text = text->substr(0, kMaxTooltipLength); |
| 283 |
| 275 // Determine the available width for the tooltip. | 284 // Determine the available width for the tooltip. |
| 276 CPoint screen_loc(position_x, position_y); | 285 CPoint screen_loc(position_x, position_y); |
| 277 View::ConvertPointToScreen(view_container_->GetRootView(), &screen_loc); | 286 View::ConvertPointToScreen(view_container_->GetRootView(), &screen_loc); |
| 278 gfx::Rect monitor_bounds = | 287 gfx::Rect monitor_bounds = |
| 279 win_util::GetMonitorBoundsForRect(gfx::Rect(screen_loc.x, screen_loc.y, | 288 win_util::GetMonitorBoundsForRect(gfx::Rect(screen_loc.x, screen_loc.y, |
| 280 0, 0)); | 289 0, 0)); |
| 281 RECT tooltip_margin; | 290 RECT tooltip_margin; |
| 282 SendMessage(window, TTM_GETMARGIN, 0, (LPARAM)&tooltip_margin); | 291 SendMessage(window, TTM_GETMARGIN, 0, (LPARAM)&tooltip_margin); |
| 283 const int available_width = monitor_bounds.width() - tooltip_margin.left - | 292 const int available_width = monitor_bounds.width() - tooltip_margin.left - |
| 284 tooltip_margin.right; | 293 tooltip_margin.right; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 keyboard_tooltip_hwnd_ = NULL; | 422 keyboard_tooltip_hwnd_ = NULL; |
| 414 } | 423 } |
| 415 } | 424 } |
| 416 | 425 |
| 417 void TooltipManager::DestroyKeyboardTooltipWindow(HWND window_to_destroy) { | 426 void TooltipManager::DestroyKeyboardTooltipWindow(HWND window_to_destroy) { |
| 418 if (keyboard_tooltip_hwnd_ == window_to_destroy) | 427 if (keyboard_tooltip_hwnd_ == window_to_destroy) |
| 419 HideKeyboardTooltip(); | 428 HideKeyboardTooltip(); |
| 420 } | 429 } |
| 421 | 430 |
| 422 } // namespace ChromeViews | 431 } // namespace ChromeViews |
| OLD | NEW |