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

Side by Side Diff: ui/views/corewm/tooltip_controller.cc

Issue 23958012: Create the Tooltip widget in Aura as needed instead of just creating it in the timer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ui/views/corewm/tooltip_controller.h" 5 #include "ui/views/corewm/tooltip_controller.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 } 80 }
81 81
82 } // namespace 82 } // namespace
83 83
84 namespace views { 84 namespace views {
85 namespace corewm { 85 namespace corewm {
86 86
87 // Displays a widget with tooltip using a views::Label. 87 // Displays a widget with tooltip using a views::Label.
88 class TooltipController::Tooltip : public views::WidgetObserver { 88 class TooltipController::Tooltip : public views::WidgetObserver {
89 public: 89 public:
90 friend class TooltipController;
91
90 Tooltip(TooltipController* controller) 92 Tooltip(TooltipController* controller)
91 : controller_(controller), 93 : controller_(controller),
92 widget_(NULL) { 94 widget_(NULL) {
93 label_.set_background( 95 label_.set_background(
94 views::Background::CreateSolidBackground(kTooltipBackground)); 96 views::Background::CreateSolidBackground(kTooltipBackground));
95 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoDropShadows)) { 97 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoDropShadows)) {
96 label_.set_border( 98 label_.set_border(
97 views::Border::CreateSolidBorder(kTooltipBorderWidth, 99 views::Border::CreateSolidBorder(kTooltipBorderWidth,
98 kTooltipBorder)); 100 kTooltipBorder));
99 } 101 }
(...skipping 16 matching lines...) Expand all
116 &line_count); 118 &line_count);
117 label_.SetText(trimmed_text); 119 label_.SetText(trimmed_text);
118 120
119 int width = max_width + 2 * kTooltipHorizontalPadding; 121 int width = max_width + 2 * kTooltipHorizontalPadding;
120 int height = label_.GetHeightForWidth(max_width) + 122 int height = label_.GetHeightForWidth(max_width) +
121 2 * kTooltipVerticalPadding; 123 2 * kTooltipVerticalPadding;
122 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoDropShadows)) { 124 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoDropShadows)) {
123 width += 2 * kTooltipBorderWidth; 125 width += 2 * kTooltipBorderWidth;
124 height += 2 * kTooltipBorderWidth; 126 height += 2 * kTooltipBorderWidth;
125 } 127 }
126 GetWidgetForWindow(window);
127 SetTooltipBounds(location, width, height); 128 SetTooltipBounds(location, width, height);
sky 2013/09/16 22:46:51 Won't this mean we potentially set the bounds only
ananta 2013/09/16 23:45:46 As per our discussion, we now destroy the tooltip
128 } 129 }
129 130
130 // Shows the tooltip. 131 // Shows the tooltip.
131 void Show() { 132 void Show() {
132 if (widget_) 133 if (widget_)
133 widget_->Show(); 134 widget_->Show();
134 } 135 }
135 136
136 // Hides the tooltip. 137 // Hides the tooltip.
137 void Hide() { 138 void Hide() {
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 if (!tooltip_window_) 522 if (!tooltip_window_)
522 return false; 523 return false;
523 aura::client::DragDropClient* client = 524 aura::client::DragDropClient* client =
524 aura::client::GetDragDropClient(tooltip_window_->GetRootWindow()); 525 aura::client::GetDragDropClient(tooltip_window_->GetRootWindow());
525 return client && client->IsDragDropInProgress(); 526 return client && client->IsDragDropInProgress();
526 } 527 }
527 528
528 TooltipController::Tooltip* TooltipController::GetTooltip() { 529 TooltipController::Tooltip* TooltipController::GetTooltip() {
529 if (!tooltip_.get()) 530 if (!tooltip_.get())
530 tooltip_.reset(new Tooltip(this)); 531 tooltip_.reset(new Tooltip(this));
532 if (tooltip_window_)
533 tooltip_->GetWidgetForWindow(tooltip_window_);
sky 2013/09/16 22:46:51 I know we discussed invoking GetWidgetForWindow, b
ananta 2013/09/16 23:45:46 This is no longer needed.
531 return tooltip_.get(); 534 return tooltip_.get();
532 } 535 }
533 536
534 bool TooltipController::IsCursorVisible() { 537 bool TooltipController::IsCursorVisible() {
535 if (!tooltip_window_) 538 if (!tooltip_window_)
536 return false; 539 return false;
537 aura::RootWindow* root = tooltip_window_->GetRootWindow(); 540 aura::RootWindow* root = tooltip_window_->GetRootWindow();
538 if (!root) 541 if (!root)
539 return false; 542 return false;
540 aura::client::CursorClient* cursor_client = 543 aura::client::CursorClient* cursor_client =
541 aura::client::GetCursorClient(root); 544 aura::client::GetCursorClient(root);
542 // |cursor_client| may be NULL in tests, treat NULL as always visible. 545 // |cursor_client| may be NULL in tests, treat NULL as always visible.
543 return !cursor_client || cursor_client->IsCursorVisible(); 546 return !cursor_client || cursor_client->IsCursorVisible();
544 } 547 }
545 548
546 int TooltipController::GetTooltipShownTimeout() { 549 int TooltipController::GetTooltipShownTimeout() {
547 std::map<aura::Window*, int>::const_iterator it = 550 std::map<aura::Window*, int>::const_iterator it =
548 tooltip_shown_timeout_map_.find(tooltip_window_); 551 tooltip_shown_timeout_map_.find(tooltip_window_);
549 if (it == tooltip_shown_timeout_map_.end()) 552 if (it == tooltip_shown_timeout_map_.end())
550 return kDefaultTooltipShownTimeoutMs; 553 return kDefaultTooltipShownTimeoutMs;
551 return it->second; 554 return it->second;
552 } 555 }
553 556
554 } // namespace corewm 557 } // namespace corewm
555 } // namespace views 558 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698