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

Side by Side Diff: chrome/browser/ui/panels/panel_browser_frame_view.cc

Issue 7055001: Make info button appear only when mouse is over the panel or the panel has focus. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 7 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/ui/panels/panel_browser_frame_view.h" 5 #include "chrome/browser/ui/panels/panel_browser_frame_view.h"
6 6
7 #include "chrome/browser/themes/theme_service.h" 7 #include "chrome/browser/themes/theme_service.h"
8 #include "chrome/browser/ui/panels/panel.h" 8 #include "chrome/browser/ui/panels/panel.h"
9 #include "chrome/browser/ui/panels/panel_browser_view.h" 9 #include "chrome/browser/ui/panels/panel_browser_view.h"
10 #include "chrome/browser/ui/panels/panel_manager.h" 10 #include "chrome/browser/ui/panels/panel_manager.h"
11 #include "content/browser/tab_contents/tab_contents.h" 11 #include "content/browser/tab_contents/tab_contents.h"
12 #include "grit/app_resources.h" 12 #include "grit/app_resources.h"
13 #include "grit/generated_resources.h" 13 #include "grit/generated_resources.h"
14 #include "grit/theme_resources.h" 14 #include "grit/theme_resources.h"
15 #include "grit/theme_resources_standard.h" 15 #include "grit/theme_resources_standard.h"
16 #include "third_party/skia/include/effects/SkGradientShader.h" 16 #include "third_party/skia/include/effects/SkGradientShader.h"
17 #include "ui/base/accessibility/accessible_view_state.h" 17 #include "ui/base/accessibility/accessible_view_state.h"
18 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/gfx/canvas_skia.h" 20 #include "ui/gfx/canvas_skia.h"
21 #include "views/controls/button/image_button.h" 21 #include "views/controls/button/image_button.h"
22 #include "views/controls/label.h" 22 #include "views/controls/label.h"
23 #include "views/painter.h" 23 #include "views/painter.h"
24 #include "views/screen.h"
24 #include "views/window/window.h" 25 #include "views/window/window.h"
25 #include "views/window/window_shape.h" 26 #include "views/window/window_shape.h"
26 27
27 #if defined(OS_LINUX) 28 #if defined(OS_LINUX)
28 #include "views/window/hit_test.h" 29 #include "views/window/hit_test.h"
29 #endif 30 #endif
30 31
31 namespace { 32 namespace {
32 33
33 // The height in pixels of the title bar. 34 // The height in pixels of the title bar.
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 123
123 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 124 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
124 active_font = new gfx::Font(rb.GetFont(ResourceBundle::BoldFont)); 125 active_font = new gfx::Font(rb.GetFont(ResourceBundle::BoldFont));
125 inactive_font = new gfx::Font(rb.GetFont(ResourceBundle::BaseFont)); 126 inactive_font = new gfx::Font(rb.GetFont(ResourceBundle::BaseFont));
126 127
127 LoadImageResources(); 128 LoadImageResources();
128 } 129 }
129 130
130 } // namespace 131 } // namespace
131 132
133 // PanelBrowserFrameView::MouseWatcher -----------------------------------------
134
135 PanelBrowserFrameView::MouseWatcher::MouseWatcher(PanelBrowserFrameView* view)
136 : view_(view),
137 in_view_(false) {
138 MessageLoopForUI::current()->AddObserver(this);
139 }
140
141 PanelBrowserFrameView::MouseWatcher::~MouseWatcher() {
142 MessageLoopForUI::current()->RemoveObserver(this);
143 }
144
145 bool PanelBrowserFrameView::MouseWatcher::IsCursorInViewBounds() const {
146 gfx::Point cursor_point = views::Screen::GetCursorScreenPoint();
147 return view_->browser_view_->GetBounds().Contains(cursor_point.x(),
148 cursor_point.y());
149 }
150
151 #if defined(OS_WIN)
152 void PanelBrowserFrameView::MouseWatcher::DidProcessMessage(const MSG& msg) {
153 switch (msg.message) {
154 case WM_MOUSEMOVE:
155 case WM_NCMOUSEMOVE:
156 case WM_MOUSELEAVE:
157 case WM_NCMOUSELEAVE:
158 HandleGlobalMouseMoveEvent();
159 break;
160 default:
161 break;
162 }
163 }
164 #else
165 void PanelBrowserFrameView::MouseWatcher::DidProcessEvent(GdkEvent* event) {
166 switch (event->type) {
167 case GDK_MOTION_NOTIFY:
168 case GDK_LEAVE_NOTIFY:
169 HandleGlobalMouseMoveEvent();
170 break;
171 default:
172 break;
173 }
174 }
175 #endif
176
177 void PanelBrowserFrameView::MouseWatcher::HandleGlobalMouseMoveEvent() {
178 bool in_view = IsCursorInViewBounds();
179 if (in_view == in_view_)
180 return;
181 in_view_ = in_view;
182 view_->OnMouseEnterOrLeaveWindow(in_view_);
183 }
184
185 // PanelBrowserFrameView -------------------------------------------------------
186
132 PanelBrowserFrameView::PanelBrowserFrameView(BrowserFrame* frame, 187 PanelBrowserFrameView::PanelBrowserFrameView(BrowserFrame* frame,
133 PanelBrowserView* browser_view) 188 PanelBrowserView* browser_view)
134 : BrowserNonClientFrameView(), 189 : BrowserNonClientFrameView(),
135 frame_(frame), 190 frame_(frame),
136 browser_view_(browser_view), 191 browser_view_(browser_view),
137 paint_state_(NOT_PAINTED), 192 paint_state_(NOT_PAINTED),
138 info_button_(NULL), 193 info_button_(NULL),
139 close_button_(NULL), 194 close_button_(NULL),
140 title_icon_(NULL), 195 title_icon_(NULL),
141 title_label_(NULL) { 196 title_label_(NULL) {
142 EnsureResourcesInitialized(); 197 EnsureResourcesInitialized();
143 frame_->set_frame_type(views::Window::FRAME_TYPE_FORCE_CUSTOM); 198 frame_->set_frame_type(views::Window::FRAME_TYPE_FORCE_CUSTOM);
144 199
145 info_button_ = new views::ImageButton(this); 200 info_button_ = new views::ImageButton(this);
146 info_button_->SetImage(views::CustomButton::BS_NORMAL, 201 info_button_->SetImage(views::CustomButton::BS_NORMAL,
147 info_button_resources.normal_image); 202 info_button_resources.normal_image);
148 info_button_->SetImage(views::CustomButton::BS_HOT, 203 info_button_->SetImage(views::CustomButton::BS_HOT,
149 info_button_resources.hover_image); 204 info_button_resources.hover_image);
150 info_button_->SetImage(views::CustomButton::BS_PUSHED, 205 info_button_->SetImage(views::CustomButton::BS_PUSHED,
151 info_button_resources.pushed_image); 206 info_button_resources.pushed_image);
152 info_button_->SetTooltipText( 207 info_button_->SetTooltipText(
153 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_ABOUT_PANEL))); 208 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_ABOUT_PANEL)));
154 info_button_->SetAccessibleName( 209 info_button_->SetAccessibleName(
155 l10n_util::GetStringUTF16(IDS_ACCNAME_ABOUT_PANEL)); 210 l10n_util::GetStringUTF16(IDS_ACCNAME_ABOUT_PANEL));
156 // TODO(jianli): Hide info button by default and show it when mouse is over 211 info_button_->SetVisible(false);
157 // panel.
158 // info_button_->SetVisible(false);
159 AddChildView(info_button_); 212 AddChildView(info_button_);
160 213
161 close_button_ = new views::ImageButton(this); 214 close_button_ = new views::ImageButton(this);
162 close_button_->SetImage(views::CustomButton::BS_NORMAL, 215 close_button_->SetImage(views::CustomButton::BS_NORMAL,
163 close_button_resources.normal_image); 216 close_button_resources.normal_image);
164 close_button_->SetImage(views::CustomButton::BS_HOT, 217 close_button_->SetImage(views::CustomButton::BS_HOT,
165 close_button_resources.hover_image); 218 close_button_resources.hover_image);
166 close_button_->SetImage(views::CustomButton::BS_PUSHED, 219 close_button_->SetImage(views::CustomButton::BS_PUSHED,
167 close_button_resources.pushed_image); 220 close_button_resources.pushed_image);
168 close_button_->SetTooltipText( 221 close_button_->SetTooltipText(
169 UTF16ToWide(l10n_util::GetStringUTF16(IDS_TOOLTIP_CLOSE_TAB))); 222 UTF16ToWide(l10n_util::GetStringUTF16(IDS_TOOLTIP_CLOSE_TAB)));
170 close_button_->SetAccessibleName( 223 close_button_->SetAccessibleName(
171 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); 224 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE));
172 AddChildView(close_button_); 225 AddChildView(close_button_);
173 226
174 title_icon_ = new TabIconView(this); 227 title_icon_ = new TabIconView(this);
175 title_icon_->set_is_light(true); 228 title_icon_->set_is_light(true);
176 AddChildView(title_icon_); 229 AddChildView(title_icon_);
177 230
178 title_label_ = new views::Label(std::wstring()); 231 title_label_ = new views::Label(std::wstring());
179 title_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 232 title_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
180 AddChildView(title_label_); 233 AddChildView(title_label_);
234
235 mouse_watcher_.reset(new MouseWatcher(this));
181 } 236 }
182 237
183 PanelBrowserFrameView::~PanelBrowserFrameView() { 238 PanelBrowserFrameView::~PanelBrowserFrameView() {
184 } 239 }
185 240
186 gfx::Rect PanelBrowserFrameView::GetBoundsForTabStrip( 241 gfx::Rect PanelBrowserFrameView::GetBoundsForTabStrip(
187 views::View* tabstrip) const { 242 views::View* tabstrip) const {
188 // Panels never show a tab strip. 243 // Panels never show a tab strip.
189 NOTREACHED(); 244 NOTREACHED();
190 return gfx::Rect(); 245 return gfx::Rect();
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 client_view_bounds_.x() - client_edges.left->width(), 527 client_view_bounds_.x() - client_edges.left->width(),
473 client_area_top, client_edges.left->width(), client_area_height); 528 client_area_top, client_edges.left->width(), client_area_height);
474 } 529 }
475 530
476 void PanelBrowserFrameView::UpdateTitleBar() { 531 void PanelBrowserFrameView::UpdateTitleBar() {
477 title_label_->SetText( 532 title_label_->SetText(
478 frame_->window_delegate()->GetWindowTitle()); 533 frame_->window_delegate()->GetWindowTitle());
479 } 534 }
480 535
481 void PanelBrowserFrameView::OnActivationChanged(bool active) { 536 void PanelBrowserFrameView::OnActivationChanged(bool active) {
537 UpdateInfoButtonVisibility(active, mouse_watcher_->IsCursorInViewBounds());
482 SchedulePaint(); 538 SchedulePaint();
483 } 539 }
540
541 void PanelBrowserFrameView::OnMouseEnterOrLeaveWindow(bool mouse_entered) {
542 UpdateInfoButtonVisibility(browser_view_->panel()->IsActive(),
543 mouse_entered);
544 }
545
546 void PanelBrowserFrameView::UpdateInfoButtonVisibility(bool active,
547 bool cursor_in_view) {
548 info_button_->SetVisible(active || cursor_in_view);
549 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698