| OLD | NEW |
| 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 "chrome/browser/ui/panels/panel_browser_frame_view.h" | 5 #include "chrome/browser/ui/panels/panel_browser_frame_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/themes/theme_service.h" | 10 #include "chrome/browser/themes/theme_service.h" |
| 11 #include "chrome/browser/themes/theme_service_factory.h" | 11 #include "chrome/browser/themes/theme_service_factory.h" |
| 12 #include "chrome/browser/ui/panels/panel.h" | 12 #include "chrome/browser/ui/panels/panel.h" |
| 13 #include "chrome/browser/ui/panels/panel_browser_view.h" | 13 #include "chrome/browser/ui/panels/panel_browser_view.h" |
| 14 #include "chrome/browser/ui/panels/panel_manager.h" | 14 #include "chrome/browser/ui/panels/panel_manager.h" |
| 15 #include "chrome/browser/ui/panels/panel_settings_menu_model.h" | |
| 16 #include "chrome/browser/ui/panels/panel_strip.h" | 15 #include "chrome/browser/ui/panels/panel_strip.h" |
| 17 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
| 18 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 19 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 20 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
| 21 #include "grit/theme_resources_standard.h" | 20 #include "grit/theme_resources_standard.h" |
| 22 #include "grit/ui_resources.h" | 21 #include "grit/ui_resources.h" |
| 23 #include "third_party/skia/include/effects/SkGradientShader.h" | 22 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 24 #include "ui/base/accessibility/accessible_view_state.h" | 23 #include "ui/base/accessibility/accessible_view_state.h" |
| 25 #include "ui/base/animation/linear_animation.h" | |
| 26 #include "ui/base/hit_test.h" | 24 #include "ui/base/hit_test.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
| 29 #include "ui/gfx/canvas.h" | 27 #include "ui/gfx/canvas.h" |
| 30 #include "ui/gfx/path.h" | 28 #include "ui/gfx/path.h" |
| 31 #include "ui/gfx/screen.h" | 29 #include "ui/gfx/screen.h" |
| 32 #include "ui/gfx/skia_util.h" | 30 #include "ui/gfx/skia_util.h" |
| 33 #include "ui/views/controls/button/image_button.h" | 31 #include "ui/views/controls/button/image_button.h" |
| 34 #include "ui/views/controls/button/menu_button.h" | |
| 35 #include "ui/views/controls/label.h" | 32 #include "ui/views/controls/label.h" |
| 36 #include "ui/views/controls/menu/menu_item_view.h" | |
| 37 #include "ui/views/controls/menu/menu_model_adapter.h" | |
| 38 #include "ui/views/controls/menu/menu_runner.h" | |
| 39 #include "ui/views/painter.h" | 33 #include "ui/views/painter.h" |
| 40 #include "ui/views/widget/widget_delegate.h" | 34 #include "ui/views/widget/widget_delegate.h" |
| 41 | 35 |
| 42 #if defined(USE_AURA) && defined(USE_X11) | 36 #if defined(USE_AURA) && defined(USE_X11) |
| 43 #include "ui/base/x/x11_util.h" | 37 #include "ui/base/x/x11_util.h" |
| 44 #endif | 38 #endif |
| 45 | 39 |
| 46 using content::WebContents; | 40 using content::WebContents; |
| 47 | 41 |
| 48 namespace { | 42 namespace { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 78 // The height and width in pixels of the icon. | 72 // The height and width in pixels of the icon. |
| 79 const int kIconSize = 16; | 73 const int kIconSize = 16; |
| 80 | 74 |
| 81 // The spacing in pixels between the title and the icon on the left, or the | 75 // The spacing in pixels between the title and the icon on the left, or the |
| 82 // button on the right. | 76 // button on the right. |
| 83 const int kTitleSpacing = 8; | 77 const int kTitleSpacing = 8; |
| 84 | 78 |
| 85 // The spacing in pixels between the close button and the right border. | 79 // The spacing in pixels between the close button and the right border. |
| 86 const int kCloseButtonAndBorderSpacing = 8; | 80 const int kCloseButtonAndBorderSpacing = 8; |
| 87 | 81 |
| 88 // The spacing in pixels between the close button and the settings button. | |
| 89 const int kSettingsButtonAndCloseButtonSpacing = 8; | |
| 90 | |
| 91 // This value is experimental and subjective. | |
| 92 const int kUpdateSettingsVisibilityAnimationMs = 120; | |
| 93 | |
| 94 // This value is experimental and subjective. | |
| 95 const int kSettingsButtonAnimationFrameRate = 50; | |
| 96 | |
| 97 // Colors used to draw active titlebar under default theme. | 82 // Colors used to draw active titlebar under default theme. |
| 98 const SkColor kActiveTitleTextDefaultColor = SK_ColorBLACK; | 83 const SkColor kActiveTitleTextDefaultColor = SK_ColorBLACK; |
| 99 const SkColor kActiveBackgroundDefaultColorStart = 0xfff0f8fa; | 84 const SkColor kActiveBackgroundDefaultColorStart = 0xfff0f8fa; |
| 100 const SkColor kActiveBackgroundDefaultColorEnd = 0xffc1d2dd; | 85 const SkColor kActiveBackgroundDefaultColorEnd = 0xffc1d2dd; |
| 101 | 86 |
| 102 // Colors used to draw inactive titlebar under default theme. | 87 // Colors used to draw inactive titlebar under default theme. |
| 103 const SkColor kInactiveTitleTextDefaultColor = 0x80888888; | 88 const SkColor kInactiveTitleTextDefaultColor = 0x80888888; |
| 104 const SkColor kInactiveBackgroundDefaultColorStart = 0xffffffff; | 89 const SkColor kInactiveBackgroundDefaultColorStart = 0xffffffff; |
| 105 const SkColor kInactiveBackgroundDefaultColorEnd = 0xffe7edf1; | 90 const SkColor kInactiveBackgroundDefaultColorEnd = 0xffe7edf1; |
| 106 | 91 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 SkPaint paint; | 166 SkPaint paint; |
| 182 paint.setStyle(SkPaint::kFill_Style); | 167 paint.setStyle(SkPaint::kFill_Style); |
| 183 paint.setAntiAlias(true); | 168 paint.setAntiAlias(true); |
| 184 paint.setShader(shader); | 169 paint.setShader(shader); |
| 185 shader->unref(); | 170 shader->unref(); |
| 186 gfx::Canvas canvas(gfx::Size(1, gradient_size), true); | 171 gfx::Canvas canvas(gfx::Size(1, gradient_size), true); |
| 187 canvas.DrawRect(gfx::Rect(0, 0, 1, gradient_size), paint); | 172 canvas.DrawRect(gfx::Rect(0, 0, 1, gradient_size), paint); |
| 188 return new SkBitmap(canvas.ExtractBitmap()); | 173 return new SkBitmap(canvas.ExtractBitmap()); |
| 189 } | 174 } |
| 190 | 175 |
| 191 const ButtonResources& GetSettingsButtonResources() { | |
| 192 static ButtonResources* buttons = NULL; | |
| 193 if (!buttons) { | |
| 194 buttons = new ButtonResources(IDR_BALLOON_WRENCH, 0, | |
| 195 IDR_BALLOON_WRENCH_H, IDR_BALLOON_WRENCH_P); | |
| 196 } | |
| 197 return *buttons; | |
| 198 } | |
| 199 | |
| 200 const ButtonResources& GetCloseButtonResources() { | 176 const ButtonResources& GetCloseButtonResources() { |
| 201 static ButtonResources* buttons = NULL; | 177 static ButtonResources* buttons = NULL; |
| 202 if (!buttons) { | 178 if (!buttons) { |
| 203 buttons = new ButtonResources(IDR_TAB_CLOSE, IDR_TAB_CLOSE_MASK, | 179 buttons = new ButtonResources(IDR_TAB_CLOSE, IDR_TAB_CLOSE_MASK, |
| 204 IDR_TAB_CLOSE_H, IDR_TAB_CLOSE_P); | 180 IDR_TAB_CLOSE_H, IDR_TAB_CLOSE_P); |
| 205 } | 181 } |
| 206 return *buttons; | 182 return *buttons; |
| 207 } | 183 } |
| 208 | 184 |
| 209 const EdgeResources& GetFrameEdges() { | 185 const EdgeResources& GetFrameEdges() { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 } | 243 } |
| 268 | 244 |
| 269 bool IsHitTestValueForResizing(int hc) { | 245 bool IsHitTestValueForResizing(int hc) { |
| 270 return hc == HTLEFT || hc == HTRIGHT || hc == HTTOP || hc == HTBOTTOM || | 246 return hc == HTLEFT || hc == HTRIGHT || hc == HTTOP || hc == HTBOTTOM || |
| 271 hc == HTTOPLEFT || hc == HTTOPRIGHT || hc == HTBOTTOMLEFT || | 247 hc == HTTOPLEFT || hc == HTTOPRIGHT || hc == HTBOTTOMLEFT || |
| 272 hc == HTBOTTOMRIGHT; | 248 hc == HTBOTTOMRIGHT; |
| 273 } | 249 } |
| 274 | 250 |
| 275 } // namespace | 251 } // namespace |
| 276 | 252 |
| 277 // Settings button animation. | |
| 278 class SettingsButtonAnimation : public ui::LinearAnimation { | |
| 279 public: | |
| 280 SettingsButtonAnimation(int duration, | |
| 281 int frame_rate, | |
| 282 ui::AnimationDelegate* delegate) | |
| 283 : ui::LinearAnimation(duration, frame_rate, delegate) {} | |
| 284 protected: | |
| 285 virtual void AnimateToState(double state) OVERRIDE {} | |
| 286 }; | |
| 287 | |
| 288 // PanelBrowserFrameView::MouseWatcher ----------------------------------------- | |
| 289 | |
| 290 PanelBrowserFrameView::MouseWatcher::MouseWatcher(PanelBrowserFrameView* view) | |
| 291 : view_(view), | |
| 292 is_mouse_within_(false) { | |
| 293 MessageLoopForUI::current()->AddObserver(this); | |
| 294 } | |
| 295 | |
| 296 PanelBrowserFrameView::MouseWatcher::~MouseWatcher() { | |
| 297 MessageLoopForUI::current()->RemoveObserver(this); | |
| 298 } | |
| 299 | |
| 300 bool PanelBrowserFrameView::MouseWatcher::IsCursorInViewBounds() const { | |
| 301 gfx::Point cursor_point = gfx::Screen::GetCursorScreenPoint(); | |
| 302 return view_->browser_view()->GetBounds().Contains(cursor_point.x(), | |
| 303 cursor_point.y()); | |
| 304 } | |
| 305 | |
| 306 #if defined(OS_WIN) | |
| 307 base::EventStatus PanelBrowserFrameView::MouseWatcher::WillProcessEvent( | |
| 308 const base::NativeEvent& event) { | |
| 309 return base::EVENT_CONTINUE; | |
| 310 } | |
| 311 | |
| 312 void PanelBrowserFrameView::MouseWatcher::DidProcessEvent( | |
| 313 const base::NativeEvent& event) { | |
| 314 switch (event.message) { | |
| 315 case WM_MOUSEMOVE: | |
| 316 case WM_NCMOUSEMOVE: | |
| 317 case WM_MOUSELEAVE: | |
| 318 case WM_NCMOUSELEAVE: | |
| 319 HandleGlobalMouseMoveEvent(); | |
| 320 break; | |
| 321 default: | |
| 322 break; | |
| 323 } | |
| 324 } | |
| 325 #elif defined(USE_AURA) && defined(USE_X11) | |
| 326 base::EventStatus PanelBrowserFrameView::MouseWatcher::WillProcessEvent( | |
| 327 XEvent* const& event) { | |
| 328 return base::EVENT_CONTINUE; | |
| 329 } | |
| 330 | |
| 331 void PanelBrowserFrameView::MouseWatcher::DidProcessEvent( | |
| 332 XEvent* const& event) { | |
| 333 if (ui::IsMotionEvent(event)) | |
| 334 HandleGlobalMouseMoveEvent(); | |
| 335 } | |
| 336 #elif defined(TOOLKIT_GTK) | |
| 337 void PanelBrowserFrameView::MouseWatcher::WillProcessEvent(GdkEvent* event) { | |
| 338 } | |
| 339 | |
| 340 void PanelBrowserFrameView::MouseWatcher::DidProcessEvent(GdkEvent* event) { | |
| 341 switch (event->type) { | |
| 342 case GDK_ENTER_NOTIFY: | |
| 343 case GDK_LEAVE_NOTIFY: | |
| 344 case GDK_MOTION_NOTIFY: | |
| 345 HandleGlobalMouseMoveEvent(); | |
| 346 break; | |
| 347 default: | |
| 348 break; | |
| 349 } | |
| 350 } | |
| 351 #endif | |
| 352 | |
| 353 void PanelBrowserFrameView::MouseWatcher::HandleGlobalMouseMoveEvent() { | |
| 354 bool is_mouse_within = IsCursorInViewBounds(); | |
| 355 if (is_mouse_within == is_mouse_within_) | |
| 356 return; | |
| 357 is_mouse_within_ = is_mouse_within; | |
| 358 view_->OnMouseEnterOrLeaveWindow(is_mouse_within_); | |
| 359 } | |
| 360 | |
| 361 // PanelBrowserFrameView ------------------------------------------------------- | |
| 362 | |
| 363 PanelBrowserFrameView::PanelBrowserFrameView(BrowserFrame* frame, | 253 PanelBrowserFrameView::PanelBrowserFrameView(BrowserFrame* frame, |
| 364 PanelBrowserView* browser_view) | 254 PanelBrowserView* browser_view) |
| 365 : BrowserNonClientFrameView(frame, browser_view), | 255 : BrowserNonClientFrameView(frame, browser_view), |
| 366 panel_browser_view_(browser_view), | 256 panel_browser_view_(browser_view), |
| 367 paint_state_(NOT_PAINTED), | 257 paint_state_(NOT_PAINTED), |
| 368 settings_button_(NULL), | |
| 369 close_button_(NULL), | 258 close_button_(NULL), |
| 370 title_icon_(NULL), | 259 title_icon_(NULL), |
| 371 title_label_(NULL), | 260 title_label_(NULL) { |
| 372 is_settings_button_visible_(false), | |
| 373 #if defined(USE_AURA) | |
| 374 has_settings_button_(panel_browser_view_->panel()->browser()->is_app()) { | |
| 375 #else | |
| 376 has_settings_button_(true) { | |
| 377 #endif | |
| 378 frame->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM); | 261 frame->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM); |
| 379 | 262 |
| 380 const ButtonResources& settings_button_resources = | |
| 381 GetSettingsButtonResources(); | |
| 382 settings_button_ = new views::MenuButton(NULL, string16(), this, false); | |
| 383 settings_button_->SetIcon(*(settings_button_resources.normal_image)); | |
| 384 settings_button_->SetHoverIcon(*(settings_button_resources.hover_image)); | |
| 385 settings_button_->SetPushedIcon(*(settings_button_resources.pushed_image)); | |
| 386 settings_button_->set_alignment(views::TextButton::ALIGN_CENTER); | |
| 387 settings_button_->set_border(NULL); | |
| 388 settings_button_->SetTooltipText( | |
| 389 l10n_util::GetStringUTF16(IDS_PANEL_WINDOW_SETTINGS_BUTTON_TOOLTIP)); | |
| 390 settings_button_->SetAccessibleName( | |
| 391 l10n_util::GetStringUTF16(IDS_PANEL_WINDOW_SETTINGS_BUTTON_TOOLTIP)); | |
| 392 settings_button_->SetVisible(is_settings_button_visible_); | |
| 393 AddChildView(settings_button_); | |
| 394 | |
| 395 const ButtonResources& close_button_resources = GetCloseButtonResources(); | 263 const ButtonResources& close_button_resources = GetCloseButtonResources(); |
| 396 close_button_ = new views::ImageButton(this); | 264 close_button_ = new views::ImageButton(this); |
| 397 close_button_->SetImage(views::CustomButton::BS_NORMAL, | 265 close_button_->SetImage(views::CustomButton::BS_NORMAL, |
| 398 close_button_resources.normal_image); | 266 close_button_resources.normal_image); |
| 399 close_button_->SetImage(views::CustomButton::BS_HOT, | 267 close_button_->SetImage(views::CustomButton::BS_HOT, |
| 400 close_button_resources.hover_image); | 268 close_button_resources.hover_image); |
| 401 close_button_->SetImage(views::CustomButton::BS_PUSHED, | 269 close_button_->SetImage(views::CustomButton::BS_PUSHED, |
| 402 close_button_resources.pushed_image); | 270 close_button_resources.pushed_image); |
| 403 close_button_->SetTooltipText( | 271 close_button_->SetTooltipText( |
| 404 l10n_util::GetStringUTF16(IDS_TOOLTIP_CLOSE_TAB)); | 272 l10n_util::GetStringUTF16(IDS_TOOLTIP_CLOSE_TAB)); |
| 405 close_button_->SetAccessibleName( | 273 close_button_->SetAccessibleName( |
| 406 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); | 274 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); |
| 407 AddChildView(close_button_); | 275 AddChildView(close_button_); |
| 408 | 276 |
| 409 title_icon_ = new TabIconView(this); | 277 title_icon_ = new TabIconView(this); |
| 410 title_icon_->set_is_light(true); | 278 title_icon_->set_is_light(true); |
| 411 AddChildView(title_icon_); | 279 AddChildView(title_icon_); |
| 412 title_icon_->Update(); | 280 title_icon_->Update(); |
| 413 | 281 |
| 414 title_label_ = new views::Label(GetTitleText()); | 282 title_label_ = new views::Label(GetTitleText()); |
| 415 title_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 283 title_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 416 title_label_->SetAutoColorReadabilityEnabled(false); | 284 title_label_->SetAutoColorReadabilityEnabled(false); |
| 417 AddChildView(title_label_); | 285 AddChildView(title_label_); |
| 418 | |
| 419 if (has_settings_button_) | |
| 420 mouse_watcher_.reset(new MouseWatcher(this)); | |
| 421 } | 286 } |
| 422 | 287 |
| 423 PanelBrowserFrameView::~PanelBrowserFrameView() { | 288 PanelBrowserFrameView::~PanelBrowserFrameView() { |
| 424 } | 289 } |
| 425 | 290 |
| 426 gfx::Rect PanelBrowserFrameView::GetBoundsForTabStrip( | 291 gfx::Rect PanelBrowserFrameView::GetBoundsForTabStrip( |
| 427 views::View* tabstrip) const { | 292 views::View* tabstrip) const { |
| 428 // Panels never show a tab strip. | 293 // Panels never show a tab strip. |
| 429 NOTREACHED(); | 294 NOTREACHED(); |
| 430 return gfx::Rect(); | 295 return gfx::Rect(); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 } | 398 } |
| 534 | 399 |
| 535 void PanelBrowserFrameView::Layout() { | 400 void PanelBrowserFrameView::Layout() { |
| 536 PanelStrip* panel_strip = panel_browser_view_->panel()->panel_strip(); | 401 PanelStrip* panel_strip = panel_browser_view_->panel()->panel_strip(); |
| 537 if (!panel_strip) | 402 if (!panel_strip) |
| 538 return; | 403 return; |
| 539 | 404 |
| 540 // Check if the width is only enough to show only the icon, or both icon | 405 // Check if the width is only enough to show only the icon, or both icon |
| 541 // and title. Hide corresponding controls accordingly. | 406 // and title. Hide corresponding controls accordingly. |
| 542 bool show_close_button = true; | 407 bool show_close_button = true; |
| 543 bool show_settings_button = true; | |
| 544 bool show_title_label = true; | 408 bool show_title_label = true; |
| 545 if (panel_strip->type() == PanelStrip::IN_OVERFLOW) { | 409 if (panel_strip->type() == PanelStrip::IN_OVERFLOW) { |
| 546 if (width() <= IconOnlyWidth()) { | 410 if (width() <= IconOnlyWidth()) { |
| 547 show_close_button = false; | 411 show_close_button = false; |
| 548 show_settings_button = false; | |
| 549 show_title_label = false; | 412 show_title_label = false; |
| 550 } else { | |
| 551 show_settings_button = false; | |
| 552 } | 413 } |
| 553 } | 414 } |
| 554 | 415 |
| 555 if (!has_settings_button_) | |
| 556 show_settings_button = false; | |
| 557 | |
| 558 close_button_->SetVisible(show_close_button); | 416 close_button_->SetVisible(show_close_button); |
| 559 settings_button_->SetVisible(show_settings_button); | |
| 560 title_label_->SetVisible(show_title_label); | 417 title_label_->SetVisible(show_title_label); |
| 561 | 418 |
| 562 // Cancel the settings button animation if the layout of titlebar is being | |
| 563 // updated. | |
| 564 if (settings_button_animator_.get() && | |
| 565 settings_button_animator_->is_animating()) { | |
| 566 settings_button_animator_->Stop(); | |
| 567 } | |
| 568 | |
| 569 // Layout the close button. | 419 // Layout the close button. |
| 570 int right = width(); | 420 int right = width(); |
| 571 if (show_close_button) { | 421 if (show_close_button) { |
| 572 gfx::Size close_button_size = close_button_->GetPreferredSize(); | 422 gfx::Size close_button_size = close_button_->GetPreferredSize(); |
| 573 close_button_->SetBounds( | 423 close_button_->SetBounds( |
| 574 width() - NonClientBorderThickness() - kCloseButtonAndBorderSpacing - | 424 width() - NonClientBorderThickness() - kCloseButtonAndBorderSpacing - |
| 575 close_button_size.width(), | 425 close_button_size.width(), |
| 576 (NonClientTopBorderHeight() - close_button_size.height()) / 2, | 426 (NonClientTopBorderHeight() - close_button_size.height()) / 2, |
| 577 close_button_size.width(), | 427 close_button_size.width(), |
| 578 close_button_size.height()); | 428 close_button_size.height()); |
| 579 right = close_button_->x(); | 429 right = close_button_->x(); |
| 580 | |
| 581 // Layout the settings button. | |
| 582 if (show_settings_button) { | |
| 583 gfx::Size settings_button_size = settings_button_->GetPreferredSize(); | |
| 584 settings_button_->SetBounds( | |
| 585 close_button_->x() - kSettingsButtonAndCloseButtonSpacing - | |
| 586 settings_button_size.width(), | |
| 587 (NonClientTopBorderHeight() - settings_button_size.height()) / 2, | |
| 588 settings_button_size.width(), | |
| 589 settings_button_size.height()); | |
| 590 right = settings_button_->x(); | |
| 591 | |
| 592 // Trace the full bounds and zero-size bounds for animation purpose. | |
| 593 settings_button_full_bounds_ = settings_button_->bounds(); | |
| 594 settings_button_zero_bounds_.SetRect( | |
| 595 settings_button_full_bounds_.x() + | |
| 596 settings_button_full_bounds_.width() / 2, | |
| 597 settings_button_full_bounds_.y() + | |
| 598 settings_button_full_bounds_.height() / 2, | |
| 599 0, | |
| 600 0); | |
| 601 } | |
| 602 } | 430 } |
| 603 | 431 |
| 604 // Layout the icon. | 432 // Layout the icon. |
| 605 int icon_y = (NonClientTopBorderHeight() - kIconSize) / 2; | 433 int icon_y = (NonClientTopBorderHeight() - kIconSize) / 2; |
| 606 title_icon_->SetBounds( | 434 title_icon_->SetBounds( |
| 607 NonClientBorderThickness() + kIconAndBorderSpacing, | 435 NonClientBorderThickness() + kIconAndBorderSpacing, |
| 608 icon_y, | 436 icon_y, |
| 609 kIconSize, | 437 kIconSize, |
| 610 kIconSize); | 438 kIconSize); |
| 611 | 439 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 return; | 502 return; |
| 675 BrowserNonClientFrameView::OnMouseCaptureLost(); | 503 BrowserNonClientFrameView::OnMouseCaptureLost(); |
| 676 } | 504 } |
| 677 | 505 |
| 678 void PanelBrowserFrameView::ButtonPressed(views::Button* sender, | 506 void PanelBrowserFrameView::ButtonPressed(views::Button* sender, |
| 679 const views::Event& event) { | 507 const views::Event& event) { |
| 680 if (sender == close_button_) | 508 if (sender == close_button_) |
| 681 frame()->Close(); | 509 frame()->Close(); |
| 682 } | 510 } |
| 683 | 511 |
| 684 void PanelBrowserFrameView::OnMenuButtonClicked(views::View* source, | |
| 685 const gfx::Point& point) { | |
| 686 if (!EnsureSettingsMenuCreated()) | |
| 687 return; | |
| 688 | |
| 689 DCHECK_EQ(settings_button_, source); | |
| 690 gfx::Point screen_point; | |
| 691 views::View::ConvertPointToScreen(source, &screen_point); | |
| 692 if (settings_menu_runner_->RunMenuAt(source->GetWidget(), | |
| 693 settings_button_, gfx::Rect(screen_point, source->size()), | |
| 694 views::MenuItemView::TOPRIGHT, views::MenuRunner::HAS_MNEMONICS) == | |
| 695 views::MenuRunner::MENU_DELETED) | |
| 696 return; | |
| 697 } | |
| 698 | |
| 699 bool PanelBrowserFrameView::ShouldTabIconViewAnimate() const { | 512 bool PanelBrowserFrameView::ShouldTabIconViewAnimate() const { |
| 700 // This function is queried during the creation of the window as the | 513 // This function is queried during the creation of the window as the |
| 701 // TabIconView we host is initialized, so we need to NULL check the selected | 514 // TabIconView we host is initialized, so we need to NULL check the selected |
| 702 // TabContents because in this condition there is not yet a selected tab. | 515 // TabContents because in this condition there is not yet a selected tab. |
| 703 WebContents* current_tab = browser_view()->GetSelectedWebContents(); | 516 WebContents* current_tab = browser_view()->GetSelectedWebContents(); |
| 704 return current_tab ? current_tab->IsLoading() : false; | 517 return current_tab ? current_tab->IsLoading() : false; |
| 705 } | 518 } |
| 706 | 519 |
| 707 SkBitmap PanelBrowserFrameView::GetFaviconForTabIconView() { | 520 SkBitmap PanelBrowserFrameView::GetFaviconForTabIconView() { |
| 708 return frame()->widget_delegate()->GetWindowIcon(); | 521 return frame()->widget_delegate()->GetWindowIcon(); |
| 709 } | 522 } |
| 710 | 523 |
| 711 void PanelBrowserFrameView::AnimationEnded(const ui::Animation* animation) { | |
| 712 settings_button_->SetVisible(is_settings_button_visible_); | |
| 713 } | |
| 714 | |
| 715 void PanelBrowserFrameView::AnimationProgressed( | |
| 716 const ui::Animation* animation) { | |
| 717 gfx::Rect animation_start_bounds, animation_end_bounds; | |
| 718 if (is_settings_button_visible_) { | |
| 719 animation_start_bounds = settings_button_zero_bounds_; | |
| 720 animation_end_bounds = settings_button_full_bounds_; | |
| 721 } else { | |
| 722 animation_start_bounds = settings_button_full_bounds_; | |
| 723 animation_end_bounds = settings_button_zero_bounds_; | |
| 724 } | |
| 725 gfx::Rect new_bounds = settings_button_animator_->CurrentValueBetween( | |
| 726 animation_start_bounds, animation_end_bounds); | |
| 727 if (new_bounds == animation_end_bounds) | |
| 728 AnimationEnded(animation); | |
| 729 else | |
| 730 settings_button_->SetBoundsRect(new_bounds); | |
| 731 } | |
| 732 | |
| 733 void PanelBrowserFrameView::AnimationCanceled(const ui::Animation* animation) { | |
| 734 AnimationEnded(animation); | |
| 735 } | |
| 736 | |
| 737 int PanelBrowserFrameView::NonClientBorderThickness() const { | 524 int PanelBrowserFrameView::NonClientBorderThickness() const { |
| 738 if (CanResize()) | 525 if (CanResize()) |
| 739 return kResizableBorderThickness + kResizableClientEdgeThickness; | 526 return kResizableBorderThickness + kResizableClientEdgeThickness; |
| 740 else | 527 else |
| 741 return kNonResizableBorderThickness + kNonResizableClientEdgeThickness; | 528 return kNonResizableBorderThickness + kNonResizableClientEdgeThickness; |
| 742 } | 529 } |
| 743 | 530 |
| 744 int PanelBrowserFrameView::NonClientTopBorderHeight() const { | 531 int PanelBrowserFrameView::NonClientTopBorderHeight() const { |
| 745 return NonClientBorderThickness() + kTitlebarHeight; | 532 return NonClientBorderThickness() + kTitlebarHeight; |
| 746 } | 533 } |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 } | 712 } |
| 926 | 713 |
| 927 string16 PanelBrowserFrameView::GetTitleText() const { | 714 string16 PanelBrowserFrameView::GetTitleText() const { |
| 928 return frame()->widget_delegate()->GetWindowTitle(); | 715 return frame()->widget_delegate()->GetWindowTitle(); |
| 929 } | 716 } |
| 930 | 717 |
| 931 void PanelBrowserFrameView::UpdateTitleBar() { | 718 void PanelBrowserFrameView::UpdateTitleBar() { |
| 932 title_label_->SetText(GetTitleText()); | 719 title_label_->SetText(GetTitleText()); |
| 933 } | 720 } |
| 934 | 721 |
| 935 void PanelBrowserFrameView::OnFocusChanged(bool focused) { | |
| 936 if (!has_settings_button_) | |
| 937 return; | |
| 938 | |
| 939 UpdateSettingsButtonVisibility(focused, | |
| 940 mouse_watcher_->IsCursorInViewBounds()); | |
| 941 SchedulePaint(); | |
| 942 } | |
| 943 | |
| 944 void PanelBrowserFrameView::OnMouseEnterOrLeaveWindow(bool mouse_entered) { | |
| 945 // Panel might be closed when we still watch the mouse event. | |
| 946 if (!panel_browser_view_->panel()) | |
| 947 return; | |
| 948 | |
| 949 if (!has_settings_button_) | |
| 950 return; | |
| 951 | |
| 952 UpdateSettingsButtonVisibility(panel_browser_view_->focused(), | |
| 953 mouse_entered); | |
| 954 } | |
| 955 | |
| 956 void PanelBrowserFrameView::UpdateSettingsButtonVisibility( | |
| 957 bool focused, bool cursor_in_view) { | |
| 958 DCHECK(has_settings_button_); | |
| 959 | |
| 960 PanelStrip* panel_strip = panel_browser_view_->panel()->panel_strip(); | |
| 961 if (!panel_strip) | |
| 962 return; | |
| 963 | |
| 964 // The settings button is not shown in the overflow state. | |
| 965 if (panel_strip->type() == PanelStrip::IN_OVERFLOW) | |
| 966 return; | |
| 967 | |
| 968 bool is_settings_button_visible = focused || cursor_in_view; | |
| 969 if (is_settings_button_visible_ == is_settings_button_visible) | |
| 970 return; | |
| 971 is_settings_button_visible_ = is_settings_button_visible; | |
| 972 | |
| 973 // Even if we're hiding the settings button, we still make it visible for the | |
| 974 // time period that the animation is running. | |
| 975 settings_button_->SetVisible(true); | |
| 976 | |
| 977 if (settings_button_animator_.get()) { | |
| 978 if (settings_button_animator_->is_animating()) | |
| 979 settings_button_animator_->Stop(); | |
| 980 } else { | |
| 981 settings_button_animator_.reset(new SettingsButtonAnimation( | |
| 982 PanelManager::AdjustTimeInterval(kUpdateSettingsVisibilityAnimationMs), | |
| 983 kSettingsButtonAnimationFrameRate, this)); | |
| 984 } | |
| 985 | |
| 986 settings_button_animator_->Start(); | |
| 987 } | |
| 988 | |
| 989 bool PanelBrowserFrameView::EnsureSettingsMenuCreated() { | |
| 990 if (settings_menu_runner_.get()) | |
| 991 return true; | |
| 992 | |
| 993 const Extension* extension = panel_browser_view_->panel()->GetExtension(); | |
| 994 if (!extension) | |
| 995 return false; | |
| 996 | |
| 997 settings_menu_model_.reset( | |
| 998 new PanelSettingsMenuModel(panel_browser_view_->panel())); | |
| 999 settings_menu_adapter_.reset( | |
| 1000 new views::MenuModelAdapter(settings_menu_model_.get())); | |
| 1001 settings_menu_ = new views::MenuItemView(settings_menu_adapter_.get()); | |
| 1002 settings_menu_adapter_->BuildMenu(settings_menu_); | |
| 1003 settings_menu_runner_.reset(new views::MenuRunner(settings_menu_)); | |
| 1004 return true; | |
| 1005 } | |
| 1006 | |
| 1007 bool PanelBrowserFrameView::CanResize() const { | 722 bool PanelBrowserFrameView::CanResize() const { |
| 1008 return panel_browser_view_->panel()->CanResizeByMouse() != | 723 return panel_browser_view_->panel()->CanResizeByMouse() != |
| 1009 panel::NOT_RESIZABLE; | 724 panel::NOT_RESIZABLE; |
| 1010 } | 725 } |
| OLD | NEW |