| 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 "chrome/browser/views/status_bubble_views.h" | 5 #include "chrome/browser/views/status_bubble_views.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "app/gfx/canvas.h" | 9 #include "app/gfx/canvas.h" |
| 10 #include "app/gfx/text_elider.h" | 10 #include "app/gfx/text_elider.h" |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 | 451 |
| 452 // StatusBubble --------------------------------------------------------------- | 452 // StatusBubble --------------------------------------------------------------- |
| 453 | 453 |
| 454 const int StatusBubbleViews::kShadowThickness = 1; | 454 const int StatusBubbleViews::kShadowThickness = 1; |
| 455 | 455 |
| 456 StatusBubbleViews::StatusBubbleViews(views::Widget* frame) | 456 StatusBubbleViews::StatusBubbleViews(views::Widget* frame) |
| 457 : offset_(0), | 457 : offset_(0), |
| 458 popup_(NULL), | 458 popup_(NULL), |
| 459 opacity_(0), | 459 opacity_(0), |
| 460 frame_(frame), | 460 frame_(frame), |
| 461 view_(NULL) { | 461 view_(NULL), |
| 462 download_shelf_is_visible_(false) { |
| 462 } | 463 } |
| 463 | 464 |
| 464 StatusBubbleViews::~StatusBubbleViews() { | 465 StatusBubbleViews::~StatusBubbleViews() { |
| 465 if (popup_.get()) | 466 if (popup_.get()) |
| 466 popup_->CloseNow(); | 467 popup_->CloseNow(); |
| 467 } | 468 } |
| 468 | 469 |
| 469 void StatusBubbleViews::Init() { | 470 void StatusBubbleViews::Init() { |
| 470 if (!popup_.get()) { | 471 if (!popup_.get()) { |
| 471 #if defined(OS_WIN) | 472 #if defined(OS_WIN) |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 view_->ResetTimer(); | 548 view_->ResetTimer(); |
| 548 | 549 |
| 549 if (view_->GetState() != StatusView::BUBBLE_HIDDEN && | 550 if (view_->GetState() != StatusView::BUBBLE_HIDDEN && |
| 550 view_->GetState() != StatusView::BUBBLE_HIDING_FADE && | 551 view_->GetState() != StatusView::BUBBLE_HIDING_FADE && |
| 551 view_->GetState() != StatusView::BUBBLE_HIDING_TIMER) { | 552 view_->GetState() != StatusView::BUBBLE_HIDING_TIMER) { |
| 552 AvoidMouse(); | 553 AvoidMouse(); |
| 553 } | 554 } |
| 554 } | 555 } |
| 555 } | 556 } |
| 556 | 557 |
| 558 void StatusBubbleViews::UpdateDownloadShelfVisibility(bool visible) { |
| 559 download_shelf_is_visible_ = visible; |
| 560 } |
| 561 |
| 557 void StatusBubbleViews::AvoidMouse() { | 562 void StatusBubbleViews::AvoidMouse() { |
| 558 // Our status bubble is located in screen coordinates, so we should get | 563 // Our status bubble is located in screen coordinates, so we should get |
| 559 // those rather than attempting to reverse decode the web contents | 564 // those rather than attempting to reverse decode the web contents |
| 560 // coordinates. | 565 // coordinates. |
| 561 gfx::Point cursor_location; | 566 gfx::Point cursor_location; |
| 562 #if defined(OS_WIN) | 567 #if defined(OS_WIN) |
| 563 POINT tmp = { 0, 0 }; | 568 POINT tmp = { 0, 0 }; |
| 564 GetCursorPos(&tmp); | 569 GetCursorPos(&tmp); |
| 565 cursor_location = tmp; | 570 cursor_location = tmp; |
| 566 #else | 571 #else |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 // and mate to the edges of the tab content). | 604 // and mate to the edges of the tab content). |
| 600 if (offset >= size_.height() - kShadowThickness * 2) { | 605 if (offset >= size_.height() - kShadowThickness * 2) { |
| 601 offset = size_.height() - kShadowThickness * 2; | 606 offset = size_.height() - kShadowThickness * 2; |
| 602 view_->SetStyle(StatusView::STYLE_BOTTOM); | 607 view_->SetStyle(StatusView::STYLE_BOTTOM); |
| 603 } else if (offset > kBubbleCornerRadius / 2 - kShadowThickness) { | 608 } else if (offset > kBubbleCornerRadius / 2 - kShadowThickness) { |
| 604 view_->SetStyle(StatusView::STYLE_FLOATING); | 609 view_->SetStyle(StatusView::STYLE_FLOATING); |
| 605 } else { | 610 } else { |
| 606 view_->SetStyle(StatusView::STYLE_STANDARD); | 611 view_->SetStyle(StatusView::STYLE_STANDARD); |
| 607 } | 612 } |
| 608 | 613 |
| 609 // Check if the bubble sticks out from the monitor. | 614 // Check if the bubble sticks out from the monitor or will obscure |
| 615 // download shelf. |
| 610 #if defined(OS_WIN) | 616 #if defined(OS_WIN) |
| 611 MONITORINFO monitor_info; | 617 MONITORINFO monitor_info; |
| 612 monitor_info.cbSize = sizeof(monitor_info); | 618 monitor_info.cbSize = sizeof(monitor_info); |
| 613 GetMonitorInfo(MonitorFromWindow(frame_->GetNativeView(), | 619 GetMonitorInfo(MonitorFromWindow(frame_->GetNativeView(), |
| 614 MONITOR_DEFAULTTONEAREST), &monitor_info); | 620 MONITOR_DEFAULTTONEAREST), &monitor_info); |
| 615 gfx::Rect monitor_rect(monitor_info.rcWork); | 621 gfx::Rect monitor_rect(monitor_info.rcWork); |
| 616 #else | 622 #else |
| 617 gfx::Rect monitor_rect; | 623 gfx::Rect monitor_rect; |
| 618 NOTIMPLEMENTED(); | 624 NOTIMPLEMENTED(); |
| 619 #endif | 625 #endif |
| 620 const int bubble_bottom_y = top_left.y() + position_.y() + size_.height(); | 626 const int bubble_bottom_y = top_left.y() + position_.y() + size_.height(); |
| 621 | 627 |
| 622 if (bubble_bottom_y + offset > monitor_rect.height()) { | 628 if (bubble_bottom_y + offset > monitor_rect.height() || |
| 629 (download_shelf_is_visible_ && |
| 630 view_->GetStyle() == StatusView::STYLE_FLOATING)) { |
| 623 // The offset is still too large. Move the bubble to the right and reset | 631 // The offset is still too large. Move the bubble to the right and reset |
| 624 // Y offset_ to zero. | 632 // Y offset_ to zero. |
| 625 view_->SetStyle(StatusView::STYLE_STANDARD_RIGHT); | 633 view_->SetStyle(StatusView::STYLE_STANDARD_RIGHT); |
| 626 offset_ = 0; | 634 offset_ = 0; |
| 627 | 635 |
| 628 int root_width = root->GetLocalBounds(true).width(); // border included. | 636 int root_width = root->GetLocalBounds(true).width(); // border included. |
| 629 // Substract border width + bubble width. | 637 // Substract border width + bubble width. |
| 630 int right_position_x = root_width - (position_.x() + size_.width()); | 638 int right_position_x = root_width - (position_.x() + size_.width()); |
| 631 popup_->SetBounds(gfx::Rect(top_left.x() + right_position_x, | 639 popup_->SetBounds(gfx::Rect(top_left.x() + right_position_x, |
| 632 top_left.y() + position_.y(), | 640 top_left.y() + position_.y(), |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 frame_->GetBounds(&frame_bounds, false); | 674 frame_->GetBounds(&frame_bounds, false); |
| 667 int mirrored_x = frame_bounds.width() - x - w; | 675 int mirrored_x = frame_bounds.width() - x - w; |
| 668 position_.SetPoint(mirrored_x, y); | 676 position_.SetPoint(mirrored_x, y); |
| 669 } else { | 677 } else { |
| 670 position_.SetPoint(x, y); | 678 position_.SetPoint(x, y); |
| 671 } | 679 } |
| 672 | 680 |
| 673 size_.SetSize(w, h); | 681 size_.SetSize(w, h); |
| 674 Reposition(); | 682 Reposition(); |
| 675 } | 683 } |
| OLD | NEW |